summaryrefslogtreecommitdiffhomepage
path: root/html/index.html
blob: ac85aa15e865179bdf2545217e35e02b9226ccba (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
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
<!DOCTYPE html>
<html>
	<head>
		<title>MIDIPLAY</title>

<style>
.button{
	width: 200px;
	height: 150px;
	font-size: 20px;
}

.selected{
  color: #FF8080;
}

.normal{
  color: #000000;
}
</style>
<script type="text/javascript">
  function get_filelist(){
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
      if (this.readyState != 4) {
        return;
      }
      if (this.status != 200) {
        document.getElementById("status").innerHTML = "HTTP error";
      } else {
        var xml = xhr.responseXML;
        var selected_file = xml.getElementsByTagName("selected")[0].childNodes[0].nodeValue;
        var list = xml.getElementsByTagName("list")[0].getElementsByTagName("filename");
        var n = list.length;
        var value = "";
        for (var i = 0; i < n; ++i) {
          var filename = list[i].childNodes[0].nodeValue;
          value += "<span class=\"" + (filename == selected_file ? "selected" : "normal") + "\">" + filename + "</span><br/>"
        }

        document.getElementById("songlist").innerHTML = value;
      }
    }

    xhr.open("POST", "midiplay.fcgi" + "?command=getlist", true);
    xhr.setRequestHeader("Content-type", "text/xml");
    xhr.send("");
  }

  function playbutton_clicked()
  {
    var action = "start";
    var element = document.getElementById("playbutton");
    if (element.innerHTML == "Play") {
      element.innerHTML = "Stop";
    } else {
      element.innerHTML = "Play";
      action = "stop";
    }

    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
      if (this.readyState != 4) {
        return;
      }
      if (this.status != 200) {
        document.getElementById("status").innerHTML = "HTTP error";
      } else {
        var xml = xhr.responseXML;
        var message = xml.getElementsByTagName("message")[0].childNodes[0].nodeValue;

        document.getElementById("status").innerHTML = message;
      }
    }

    xhr.open("POST", "midiplay.fcgi" + "?command=" + action, true);
    xhr.setRequestHeader("Content-type", "text/xml");
    xhr.send("");
  }

  function songlist_clicked()
  {
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
      if (this.readyState != 4) {
        return;
      }
      if (this.status != 200) {
        document.getElementById("status").innerHTML = "HTTP error";
      } else {
        var xml = xhr.responseXML;
        var message = xml.getElementsByTagName("message")[0].childNodes[0].nodeValue;

        document.getElementById("status").innerHTML = message;

        get_filelist(); // trigger reload
      }
    }

    xhr.open("POST", "midiplay.fcgi" + "?command=setfile", true);
    xhr.setRequestHeader("Content-type", "text/xml");
    xhr.send("<data><value>magic.midi</value></data>");
  }

  function startup() {
    document.getElementById("playbutton").onclick = playbutton_clicked;
    document.getElementById("songlist").onclick = songlist_clicked;

    get_filelist();
  }

</script>
	</head>
	<body onload="startup();">
MIDIPLAY

<br/>
<br/>
<div id="songlist">
(Loading Songlist...)
</div>
<br/>
<br/>
<button id="playbutton" class="button">Play</button>

<br>
<div>
  Status: <span id="status">ok</span>
</div>

	</body>
</html>