-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReteRNN.js
63 lines (43 loc) · 1.64 KB
/
ReteRNN.js
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
var music_rnn, rnnPlayer;
var melody1;
Players();
inizializzamodello();
function Players() {
MagentaPlayer = new mm.Player();
MagentaPlayer = new mm.SoundFontPlayer('https://storage.googleapis.com/magentadata/js/soundfonts/sgm_plus');
}
function melodysequence() {
melody1 = {
notes: [
{pitch: noteArray[0], startTime: timeArray[0], endTime: timeArray[1]},
{pitch: noteArray[2], startTime: timeArray[2], endTime: timeArray[3]},
{pitch: noteArray[4], startTime: timeArray[4], endTime: timeArray[5]},
{pitch: noteArray[6], startTime: timeArray[6], endTime: timeArray[7]},
{pitch: noteArray[8], startTime: timeArray[8], endTime: timeArray[9]},
{pitch: noteArray[10], startTime: timeArray[10], endTime: timeArray[11]},
{pitch: noteArray[12], startTime: timeArray[12], endTime: timeArray[13]},
{pitch: noteArray[14], startTime: timeArray[14], endTime: timeArray[15]},
{pitch: noteArray[16], startTime: timeArray[16], endTime: timeArray[17]},
{pitch: noteArray[18], startTime: timeArray[18], endTime: timeArray[19]},
],
tempos: [{
time: 0,
qpm: 120
}],
totalTime: timeArray[19]
};
playRNN();
}
function inizializzamodello(){
// Initialize model
music_rnn = new mm.MusicRNN('https://storage.googleapis.com/magentadata/js/checkpoints/music_rnn/melody_rnn');
music_rnn.initialize();
}
var rnn_steps = 20;
var rnn_temperature = 1.5;
function playRNN() {
const qns = mm.sequences.quantizeNoteSequence(melody1, 2);
music_rnn
.continueSequence(qns, rnn_steps, rnn_temperature)
.then((sample) => MagentaPlayer.start(sample))
}