aboutsummaryrefslogtreecommitdiff
path: root/views/script/core_music.js
blob: d1e861953c86c33d35a8b96aeb201c857b64cbc3 (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
global.csng = null;
global.csp1 = null;
global.csp2 = null;
global.cspn = 1;
const musicIpc = require('electron').ipcRenderer;

musicIpc.on('setmusic', (event, args) => {
    song = args;

    if (song !== null && song !== "" && csng !== song) {
        if (cspn === 1) {
            if (csp1 !== null) {
                csi1 = setInterval(() => {
                    if (csp1.volume <= 0.05) {
                        csp1.pause();
                        clearInterval(csi1);
                        return;
                    }
                    csp1.volume = csp1.volume - 0.05;
                }, 100)
            }
            csp2 = new Audio(song);
            csp2.volume = 0;
            csp2.loop = true;
            csp2.play();
            csi2 = setInterval(() => {
                if (csp2.volume >= 0.95) {
                    clearInterval(csi2);
                    return;
                }
                csp2.volume = csp2.volume + 0.05;
            }, 100)
            csng = song;
            cspn = 2;
        } else {
            if (csp2 !== null) {
                csi2 = setInterval(() => {
                    if (csp2.volume <= 0.05) {
                        csp2.pause();
                        clearInterval(csi2);
                        return;
                    }
                    csp2.volume = csp2.volume - 0.05;
                }, 100)
            }
            csp1 = new Audio(song);
            csp1.volume = 0;
            csp1.loop = true;
            csp1.play();
            csi1 = setInterval(() => {
                if (csp1.volume >= 0.95) {
                    clearInterval(csi1);
                    return;
                }
                csp1.volume = csp1.volume + 0.05;
            }, 100)
            csng = song;
            cspn = 1;
        }
    }
})

musicIpc.on('fademusic', (event) => {
    if (cspn === 1) {
        if (csp1 !== null) {
            csi1 = setInterval(() => {
                if (csp1.volume <= 0.5) {
                    clearInterval(csi1);
                    return;
                }
                csp1.volume = csp1.volume - 0.05;
            }, 100)
        }
    } else {
        if (csp2 !== null) {
            csi2 = setInterval(() => {
                if (csp2.volume <= 0.5) {
                    clearInterval(csi2);
                    return;
                }
                csp2.volume = csp2.volume - 0.05;
            }, 100)
        }
    }
})

musicIpc.on('unfademusic', (event) => {
    if (cspn === 1) {
        if (csp1 !== null) {
            csi1 = setInterval(() => {
                if (csp1.volume >= 0.95) {
                    clearInterval(csi1);
                    return;
                }
                csp1.volume = csp1.volume + 0.05;
            }, 100)
        }
    } else {
        if (csp2 !== null) {
            csi2 = setInterval(() => {
                if (csp2.volume >= 0.95) {
                    clearInterval(csi2);
                    return;
                }
                csp2.volume = csp2.volume + 0.05;
            }, 100)
        }
    }
})