File size: 2,166 Bytes
b0bfea8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
 * other.js
 * purpose: contains some useful functions that don't belong in any specific category
 */

/**
 * Formats the given seconds to nice readable time
 * @param totalSeconds {number} time in seconds
 * @return {{seconds: number, minutes: number, time: string}}
 */
export function formatTime(totalSeconds)
{
    totalSeconds = Math.floor(totalSeconds);
    let minutes = Math.floor(totalSeconds / 60);
    let seconds = Math.round(totalSeconds - (minutes * 60));
    return {
        "minutes": minutes,
        "seconds": seconds,
        "time": `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`
    };
}

/**
 * @param fileName {string}
 * @returns {string}
 */
export function formatTitle(fileName)
{
    return fileName
        .trim()
        .replaceAll(".mid", "")
        .replaceAll(".kar", "")
        .replaceAll(".rmi", "")
        .replaceAll(".xmf", "")
        .replaceAll(".mxmf", "")
        .replaceAll("_", " ")
        .trim();
}

/**
 * Does what it says
 * @param arr {number[]|Uint8Array}
 * @returns {string}
 */
export function arrayToHexString(arr)
{
    let hexString = "";
    
    for (let i = 0; i < arr.length; i++)
    {
        const hex = arr[i].toString(16).padStart(2, "0").toUpperCase();
        hexString += hex;
        hexString += " ";
    }
    
    return hexString;
}

/**
 * @param eventData {Uint8Array}
 * @returns {Uint8Array}
 */
export function sanitizeKarLyrics(eventData)
{
    // for KAR files:
    // https://www.mixagesoftware.com/en/midikit/help/HTML/karaoke_formats.html
    // "/" is the newline character
    // "\" is also the newline character
    // "\" ASCII code is 92
    // "/" ASCII code is 47
    // newline ASCII code is 10
    const sanitized = [];
    for (let byte of eventData)
    {
        if (byte === 47 || byte === 92)
        {
            byte = 10;
        }
        sanitized.push(byte);
    }
    return new Uint8Array(sanitized);
}

export const consoleColors = {
    warn: "color: orange;",
    unrecognized: "color: red;",
    info: "color: aqua;",
    recognized: "color: lime",
    value: "color: yellow; background-color: black;"
};