-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample.html
More file actions
209 lines (209 loc) · 7.11 KB
/
example.html
File metadata and controls
209 lines (209 loc) · 7.11 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SSSynthesiser.js example</title>
<script src="SSSynthesiser.js"></script>
<script>
var initialized = false;
var sssynthesiser = null;
var initInfo = null;
var loopMode=0;
function initSSSynthesiser() {
if (!initialized) {
console.log("initSSSynthesiser");
initInfo = document.getElementById("initInfo");
initInfo.innerHTML = 'loading...';
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open('GET', "http://molgav.nn.ru/x/sviridovtimeforward.molgav", true);
xmlHttpRequest.onload = function () {
var o = JSON.parse(xmlHttpRequest.response);
sssynthesiser = new SSSynthesiser(o);
sssynthesiser.moveToNextPosition = xMoveToNextPosition;
initialized = true;
initInfo = document.getElementById("initInfo");
startInfoLoop();
};
xmlHttpRequest.onerror = function (xmlHttpRequestProgressEvent) {
console.log("error " + xmlHttpRequestProgressEvent);
};
xmlHttpRequest.send();
}
}
function xMoveToNextPosition() {
console.log("xMoveToNextPosition "+loopMode+"/"+sssynthesiser.currentX+"/"+sssynthesiser.currentY);
if(loopMode==0){
sssynthesiser.findAndMoveToNextPosition();
return;
}
if(loopMode==1){
sssynthesiser.currentX = 0;
sssynthesiser.currentY = 0;
sssynthesiser.currentPosition = sssynthesiser.findPosition(sssynthesiser.currentX, sssynthesiser.currentY);
return;
}
if(loopMode==2){
if((sssynthesiser.currentX == 3 && sssynthesiser.currentY == 2) || sssynthesiser.currentY < 1 || sssynthesiser.currentY >2 ){
sssynthesiser.currentX = 0;
sssynthesiser.currentY = 1;
sssynthesiser.currentPosition = sssynthesiser.findPosition(sssynthesiser.currentX, sssynthesiser.currentY);
return;
}
else{
sssynthesiser.findAndMoveToNextPosition();
}
}
if(loopMode==3){
if((sssynthesiser.currentX == 3 && sssynthesiser.currentY == 4) || sssynthesiser.currentY < 3){
sssynthesiser.currentX = 0;
sssynthesiser.currentY = 3;
sssynthesiser.currentPosition = sssynthesiser.findPosition(sssynthesiser.currentX, sssynthesiser.currentY);
return;
}
else{
sssynthesiser.findAndMoveToNextPosition();
}
}
}
function startInfoLoop() {
var info = "loop "+loopMode;
if (sssynthesiser != null) {
if (sssynthesiser.currentPosition != null) {
info = info + ", position " + sssynthesiser.currentPosition.left + ":" + sssynthesiser.currentPosition.top + ", sixteenth " + sssynthesiser.mix16Counter;
}
}
info = info + ", audiocontext time " + sssynthesiser.audioContext.currentTime;
initInfo.innerHTML = info;
setTimeout(startInfoLoop, 333);
}
function ready() {
if (!initialized) {
alert("Press Initialize first.");
return false;
} else {
return true;
}
}
function startPlay() {
if (ready()) {
if (!sssynthesiser.stopped) {
return;
}
console.log("startPlay");
sssynthesiser.startPlaySong();
}
}
function stopPlay() {
if (ready()) {
if (sssynthesiser.stopped) {
return;
}
console.log("stopPlay");
sssynthesiser.stopPlaySong();
}
}
function rewind() {
if (ready()) {
console.log("rewind");
sssynthesiser.rewind();
}
}
function muteDrums() {
if (ready()) {
console.log("muteDrums");
for (var i = 0; i < sssynthesiser.song.samples.length; i++) {
if (sssynthesiser.song.samples[i].isDrum) {
sssynthesiser.song.samples[i].volume = 0;
} else {
sssynthesiser.song.samples[i].volume = 0.7;
}
}
}
}
function muteInstruments() {
if (ready()) {
console.log("muteInstruments");
for (var i = 0; i < sssynthesiser.song.samples.length; i++) {
if (!sssynthesiser.song.samples[i].isDrum) {
sssynthesiser.song.samples[i].volume = 0;
} else {
sssynthesiser.song.samples[i].volume = 0.7;
}
}
sssynthesiser.findSampleBySubPath("drums/000/Chaos_128/061_046-046_60_-4600.0_8-34789_32000").volume = 0.25;
}
}
function muteNone() {
if (ready()) {
console.log("muteNone");
for (var i = 0; i < sssynthesiser.song.samples.length; i++) {
sssynthesiser.song.samples[i].volume = 0.7;
}
sssynthesiser.findSampleBySubPath("drums/000/Chaos_128/061_046-046_60_-4600.0_8-34789_32000").volume = 0.25;
}
}
function mode(m){
loopMode=m;
}
function hitDrum(s){
if (ready()) {
sssynthesiser.playSample(sssynthesiser.findSampleBySubPath(s),2000);
}
}
function hitKey(n){
if (ready()) {
sssynthesiser.playKey(sssynthesiser.findSampleBySubPath("instruments/000/Chaos_000/003_048-052_60_-5000_8-32231_22050"),1000,n);
}
}
function hitChord(ns){
if (ready()) {
sssynthesiser.playChord(sssynthesiser.findSampleBySubPath("instruments/034"),1000,ns);
}
}
</script>
</head>
<body>
<h1>SSSynthesiser.js example</h1>
<p>How to use <a href="https://github.com/surikov/SSSynthesiser.js" target="_blank">SSSynthesiser.js</a> to play <a href="http://molgav.nn.ru/?song=x2/1433934921.66" target="_blank">G.Sviridov 'Time, Forward!'</a>.</p>
<ul>
<li><a href="javascript:initSSSynthesiser();">Initialize</a> [<span id="initInfo">not initialized</span>]</li>
<li><a href="javascript:startPlay();">Play</a></li>
<li><a href="javascript:stopPlay();">Stop</a></li>
<li><a href="javascript:rewind();">Rewind</a></li>
<li>Mute <a href="javascript:muteDrums();">drums</a> | <a href="javascript:muteInstruments();">instruments</a> | <a href="javascript:muteNone();">none</a></li>
<li>Loop
<ul>
<li><a href="javascript:mode(0);">whole song</a></li>
<li><a href="javascript:mode(1);">piece 1</a>
<ul>
<li>0:0</li>
</ul>
</li>
<li><a href="javascript:mode(2);">piece 2</a>
<ul>
<li>0:1, 1:1, 2:1, 3:1<br/>
0:2, 1:2, 2:2, 3:2</li>
</ul>
</li>
<li><a href="javascript:mode(3);">piece 3</a>
<ul>
<li>0:3, 1:3, 2:3, 3:3<br/>
0:4, 1:4, 2:4, 3:4</li>
</ul>
</li>
</ul>
</li>
<li>Hit drum <a href="javascript:hitDrum('drums/000/Chaos_128/001_035-035_60_-3500.0_8-16861_44100');">bass</a> | <a href="javascript:hitDrum('drums/000/Chaos_128/004_038-038_60_-3800.0_8-17828_44100');">snare</a> | <a href="javascript:hitDrum('drums/000/Chaos_128/061_046-046_60_-4600.0_8-34789_32000');">hihat</a></li>
<li>Hit piano <a href="javascript:hitKey(45);">A</a> | <a href="javascript:hitKey(47);">H</a> | <a href="javascript:hitKey(48);">C</a> | <a href="javascript:hitKey(50);">D</a> | <a href="javascript:hitKey(52);">E</a> | <a href="javascript:hitKey(53);">F</a> | <a href="javascript:hitKey(55);">G</a> | <a href="javascript:hitKey(57);">a</a></li>
<li>Hit chord <a href="javascript:hitChord([45,52,57,61,64]);">A</a>
| <a href="javascript:hitChord([45,52,57,60,64]);">Am</a>
| <a href="javascript:hitChord([48,52,55,60,64]);">C</a>
| <a href="javascript:hitChord([48,51,55,60,67]);">Cm</a>
</li>
</ul>
<p>See JSON <a href="http://molgav.nn.ru/x/sviridovtimeforward.molgav" target="_blank">data</a> for example.</p>
<h2>More examples</h2>
<p>WebGL <a href="http://molgav.nn.ru/babylonsynth/" target="_blank">demo</a> for desktop/mobile.</p>
</body>
</html>