File size: 2,208 Bytes
0442d80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Ultrastar Converter"""

from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue

def real_bpm_to_ultrastar_bpm(real_bpm: float) -> float:
    """Converts real BPM to UltraStar BPM"""
    # The UltraStar BPM info is a fourth beat of the real BPM
    ultrastar_bpm = real_bpm / 4
    return ultrastar_bpm


def ultrastar_bpm_to_real_bpm(ultrastar_bpm: float) -> float:
    """Converts UltraStar BPM to real BPM"""
    # The UltraStar BPM info is a fourth beat of the real BPM
    bpm = ultrastar_bpm * 4
    return bpm


def second_to_beat(seconds: float, real_bpm: float) -> float:
    """Converts seconds to beat"""
    # BPM = 60 * beat / T
    # T * BPM = 60 * beat
    # beat = T * BPM / 60
    beat = seconds * real_bpm / 60
    return beat


def beat_to_second(beat: float, real_bpm: float) -> float:
    """Converts beat to seconds"""

    seconds = beat * 60 / real_bpm
    return seconds


def midi_note_to_ultrastar_note(midi_note: int) -> int:
    """Converts Midi note to UltraStar note"""

    # C4 == 48 in Midi
    ultrastar_note = midi_note - 48
    return ultrastar_note


def ultrastar_note_to_midi_note(ultrastar_note: int) -> int:
    """Converts UltraStar note to Midi note"""

    # C4 == 48 in Midi
    midi_note = ultrastar_note + 48
    return midi_note


def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float:
    """Calculates the start time from the Ultrastar txt"""

    gap = int(ultrastar_class.gap) / 1000
    real_bpm = ultrastar_bpm_to_real_bpm(
        float(ultrastar_class.bpm.replace(",", "."))
    )
    start_time = (
        beat_to_second(int(ultrastar_class.startBeat[pos]), real_bpm) + gap
    )
    return start_time


def get_end_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float:
    """Calculates the end time from the Ultrastar txt"""

    gap = int(ultrastar_class.gap) / 1000
    real_bpm = ultrastar_bpm_to_real_bpm(
        float(ultrastar_class.bpm.replace(",", "."))
    )
    end_time = (
        beat_to_second(
            int(ultrastar_class.startBeat[pos])
            + int(ultrastar_class.durations[pos]),
            real_bpm,
        )
        + gap
    )
    return end_time