-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.html
355 lines (301 loc) · 10.4 KB
/
play.html
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LoopScript: Play</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
body {
padding-top: 70px;
padding-bottom: 30px;
}
.listenclick {
cursor: pointer;
}
.well {
margin-bottom: 2px;
}
</style>
</head>
<body>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-1.11.0.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">LoopScript</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li >
<a href="/">Home</a>
</li>
<li >
<a href="learn.html">Learn</a>
</li>
<li class="active">
<a href="play.html">Play</a>
</li>
<li >
<a href="source.html">Get it</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container" role="main">
<script src="ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lz-string-1.3.3-min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/loopscript.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.urlshortener.min.js" type="text/javascript" charset="utf-8"></script>
<style>
#editor {
width: 100%;
height: 350px;
border: 1px solid #aaaaaa;
}
#output {
width: 100%;
height: 100px;
font-family: monospace;
overflow: auto;
border: 1px solid #aaaaaa;
display: none;
}
#beatmaker {
display: none;
}
#beatinput {
width: 100%;
margin-bottom: 10px;
font-family: monospace;
overflow: auto;
border: 1px solid #aaaaaa;
}
#shorturl {
font-family: monospace;
font-size: 1.5em;
}
#beatoutput {
width: 100%;
height: 450px;
font-family: monospace;
white-space: pre;
overflow: auto;
border: 1px solid #aaaaaa;
}
.actions {
font-size: 1.5em;
}
.compile {
font-weight: 900;
}
</style>
<h1>Playground</h1>
Edit the LoopScript below and hit "Compile" to turn it into audio.<br>
If you make a mistake, you should be able to read it in the output below the editor once you've attempted to compile.<br>
<br>
<pre>
H-L are the black keys:
H I J K L
C D E F G A B
</pre>
<div id="editor"></div>
<div class="actions">
[<a href="#" class="compile" onclick="render(editor.getValue(), '#renderedlink', true, true)">Compile</a>]
[<a href="#" onclick="shareUrl()">Permalink</a>]
[<a href="#" onclick="shortUrl()">Short URL</a>]
<span class="dropdown theme-dropdown">
[<a id="dropdownMenu1" href="#" role="button" class="dropdown-toggle" data-toggle="dropdown">Example<b class="caret"></b></a>]
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('first')">Your First LoopScript</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('notes')">Note Overrides</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('length')">Note Lengths</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('chocobo')">Chocobo Theme</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('kick')">Bass Kick</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('kickpattern')">Simple Kick Pattern</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('wiggle')">Wiggle</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('motto')">Drake - The Motto</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('beatmaker')">BeatMaker Test Bed</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="example('gambino3005')">Childish Gambino - 3005 (intro)</a></li>
</ul>
</span>
[<a href="#" onclick="beatMaker()">BeatMaker</a>]
</div>
<div id="output">
Compile output:<br>
<br>
</div>
<br>
<span id="renderedlink"></span>
<div id="shorturl"></div>
<div id="beatmaker">
<h1>BeatMaker</h1>
BeatMaker is a convenience tool for coming up with pattern statements.<br>
Simply click in the box below and use the alphabet keys as your piano. After you've repeated the pattern exactly twice, wait for BeatMaker to make a best guess on BPM and a series of possible patterns to use.<br>
<br>
Use the <a href="#" onclick="if(confirm('Replace the current LoopScript with the BeatMaker Test Bed?')) { example('beatmaker'); }">BeatMaker Test Bed sample script</a> to see a simple use case. (If you use this, use K and C for kick and clap, respectively.)<br>
<br>
<input type="text" id="beatinput" readonly>
<div id="beatoutput">(BeatMaker output will go here.)<br>
<br>
</div>
<br>
</div>
<script>
// from http://css-tricks.com/snippets/javascript/get-url-variables/
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
// return(false);
return "";
}
// from http://stackoverflow.com/questions/1173194/select-all-div-text-with-single-mouse-click
function selectText(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection()) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
}
}
jQuery.urlShortener.settings.apiKey='AIzaSyDrlWADAWOaDClnMAWh-316Jo8cDIS8qo4';
var editor = ace.edit("editor");
editor.setTheme("ace/theme/github");
editor.getSession().setMode("ace/mode/loopscript");
editor.setHighlightActiveLine(false);
editor.setPrintMarginColumn(0);
var loopscript = require("./loopscript");
var examples = require("./examples");
function render(scriptText, outputID, showOutput, showSaveAs)
{
if(showOutput)
{
$('#output').css("display", "block");
}
var lsOutput = loopscript.render({
script: scriptText,
imageWidth: 300,
imageHeight: 50,
imageWaveformColor: [0, 134, 179],
log: {
verbose: function(text) {
if(showOutput)
{
$('#output').append(text + "<br>");
var o = document.getElementById("output");
o.scrollTop = o.scrollHeight;
}
},
error: function(text) {
if(showOutput)
{
$('#output').append("<span class=\"error\">" + text + "</span><br>");
var o = document.getElementById("output");
o.scrollTop = o.scrollHeight;
}
}
}
});
var html = "<img src=\""+lsOutput.imageUrl+"\"><br>";
html += "<audio src="+lsOutput.wavUrl+" controls preload=\"auto\" autobuffer></audio>";
if(showSaveAs) {
html += "<a href="+lsOutput.wavUrl+"><br>Right click here to Save As...</a>";
}
$(outputID).html(html);
}
function replaceText(text)
{
if(text != null)
{
editor.setValue(text);
editor.clearSelection();
}
}
function example(name)
{
replaceText(examples[name]);
}
function permalink()
{
var encodedScript = LZString.compressToBase64(editor.getValue());
var loc = "" + window.location;
var urlPieces = loc.split("?");
urlPieces = urlPieces[0].split("#");
var url = urlPieces[0] + "?s=" + encodedScript;
return url;
}
function shareUrl()
{
var url = permalink();
// window.prompt("Copy to clipboard:", url);
window.location = url;
}
function shortUrl()
{
$('#shorturl').html("Generating short url ...");
jQuery.urlShortener({
longUrl: permalink(),
success: function (shortUrl) {
$('#shorturl').html(shortUrl);
selectText('shorturl');
},
error: function(err)
{
$('#shorturl').html("Failed to create short URL.");
}
});
}
function beatMaker()
{
$('#beatmaker').toggle();
}
$(function() {
editor.resize();
var encodedScript = getQueryVariable("s");
var decodedScript = null;
if(encodedScript.length > 0)
{
decodedScript = LZString.decompressFromBase64(encodedScript);
}
if(typeof decodedScript == "string")
{
replaceText(decodedScript);
}
else
{
example('first');
}
var beatmaker = require("./beatmaker");
});
</script>
</div>
</body>
</html>