File size: 2,378 Bytes
d3a278d
 
 
 
 
 
 
 
adf6362
d3a278d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
function compose() {

    // Get the value of the select with id selected_midi_program.
    var selected_music_style = document.getElementById("selected_music_style").value;
    var selected_density = document.getElementById("selected_density").value;
    var selected_temperature = document.getElementById("selected_temperature").value;

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "compose", true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({
        music_style: selected_music_style,
        density: selected_density,
        temperature: selected_temperature
    }));

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var response = JSON.parse(xhr.responseText);
            console.log(response);

            if (response.status == "OK") {

                // Replace the inner html of the div with id token_sequence with the token sequence.
                document.getElementById("token_sequence").innerHTML = response.tokens;

                // Replace the source of the audio element with id audio..
                var audio = document.getElementById("audio_id");
                audio.src = response.audio;

                // Replace the source of the image element with id image.
                var image = document.getElementById("image_id");
                image.src = response.image;
                
            }
            else {
                alert("Error: " + response.error);
            }
        }
    }
}


function post_command(command_name, command_parameters, reload) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/command", true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({command_name: command_name, command_parameters: command_parameters}));

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var response = JSON.parse(xhr.responseText);
            if (response.status == "OK") {

                // Reload the page if requested.
                if (reload) {
                    console.log("Reloading.");
                    load_cells();
                }
                
            }
            else {
                alert("Error: " + response.error);
            }
        }
    }
}