-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
136 lines (127 loc) · 4.88 KB
/
Copy pathindex.html
File metadata and controls
136 lines (127 loc) · 4.88 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Bach-machine</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/combine/npm/tone@14.7.58,npm/@magenta/music@1.23.1/es6/core.js,npm/focus-visible@5,npm/html-midi-player@1.4.0"></script>
</head>
<body>
<div class="content">
<div class="title">
<h1>Bach-machine</h1>
<p>Su generador inteligente de corales</p>
</div>
<div id="home-msg" align="center">
<br>
<label for="tonos">Tono:</label>
<select class="select" id="tonos">
<option aria-label="do bemol" value="ces">Do♭</option>
<option aria-label="do" value="c" selected>Do</option>
<option aria-label="do sostenido" value="cis">Do♯</option>
<option aria-label="re bemol" value="des">Re♭</option>
<option aria-label="re" value="d">Re</option>
<option aria-label="re sostenido" value="dis">Re♯</option>
<option aria-label="mi bemol" value="ees">Mi♭</option>
<option aria-label="mi" value="e">Mi</option>
<option aria-label="fa" value="f">Fa</option>
<option aria-label="fa sostenido" value="fis">Fa♯</option>
<option aria-label="sol bemol" value="ges">Sol♭</option>
<option aria-label="sol" value="g">Sol</option>
<option aria-label="sol sostenido" value="gis">Sol♯</option>
<option aria-label="la bemol" value="aes">La♭</option>
<option aria-label="la" value="a">La</option>
<option aria-label="la sostenido" value="ais">La♯</option>
<option aria-label="si bemol" value="bes">Si♭</option>
<option aria-label="si" value="b">Si</option>
</select>
<label for="modo">Modo:</label>
<select class="select" id="modo">
<option value="major" selected>Mayor</option>
<option value="minor">menor</option>
</select>
<br><br>
<input class="select" type="button" value="Generar" onclick="generate()">
<br>
</div>
<div class="flex-content" id="loading"></div>
<div class="flex-content" id="cont"></div>
</div>
<script>
function showLoading() {
document.getElementById('loading').innerHTML = `<img width="50px" src="files/bach.gif" alt="Cargando...">`;
document.getElementById('loading').style.display = 'flex';
}
function hideLoading() {
document.getElementById('loading').innerHTML = ``
document.getElementById('loading').style.display = 'none';
}
function generate() {
const midiPlayer = document.querySelector("div.midi-button midi-player")
if (midiPlayer) { midiPlayer.player.stop(); }
document.getElementById('cont').innerHTML = ``
showLoading();
const host = `https://bach-machine-02a43fd154c6.herokuapp.com`
const key = document.getElementById('tonos').value;
const mode = document.getElementById('modo').value;
const url = `${host}/choral/${key}/${mode}`;
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
mode: 'cors'
})
.then(response => {
if (!response.ok) {
throw new Error(`Error: ${response.statusText} (${response.status})`);
}
return response.text();
})
.then(text => {
try {
const data = JSON.parse(text);
const pdfId = data.pdf;
const midiId = data.midi;
const pdfUrl = `${host}/pdf/${pdfId}`;
const midiUrl = `${host}/midi/${midiId}`;
const midiPlayer = `<div class="midi-button">
<midi-player
sound-font="https://storage.googleapis.com/magentadata/js/soundfonts/sgm_plus"
src="${midiUrl}">
</midi-player>
<a id="downloadLink" href="#" download="choral${midiId}.mid"><img alt="Midi file" src="files/audioDownload52.png"></a>
</div>`;
const pdfIframe = `<iframe src="${pdfUrl}" class="pdf-iframe"></iframe>`;
fetch(midiUrl)
.then(response => response.blob())
.then(blob => {
// Crea un URL para el Blob y lo asigna al enlace de descarga
const url = URL.createObjectURL(blob);
const downloadLink = document.getElementById("downloadLink");
downloadLink.href = url;
})
.catch(error => {
console.error("Error al descargar el archivo:", error);
});
hideLoading();
document.getElementById('cont').innerHTML = `${midiPlayer}${pdfIframe}`;
} catch (error) {
throw new Error(`Error parsing JSON: ${error.message}`);
}
})
.catch(error => {
hideLoading();
document.getElementById('cont').innerHTML = `<div><img width="50px" alt="Bach" src="files/bach.png"></div><div>${error.message}</div>`;
});
}
</script>
<br><br>
</body>
<footer>
<a href="mailto:sergio-flor@outlook.es"><img alt="Mail" src="files/mail32.png"></a>
<a href="https://github.com/balath/pfg"><img alt="Github Repo" src="files/github32.png"></a>
</footer>
</html>