-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexample.html
137 lines (120 loc) · 3.53 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script type="text/javascript" src="synth.js"></script>
<script type="text/javascript">
var context = new webkitAudioContext();
var loop;
function initLoop() {
var drum = context.createDrum();
drum.connect(context.destination);
var hihat = context.createHiHat();
hihat.connect(context.destination);
loop = new Loop();
loop.setInstruments({
drum:drum,
hihat:hihat
});
loop.setBPM(120);
loop.setBeatUnit(1 / 16);
loop.setSequences({
drum: '* * * * * * * *****',
hihat: ' * '
});
loop.onPlay = function(track, position){
var background = $('.sequenceBackground[data-sequence="'+track+'"]');
$('.highlighted', background).removeClass('highlighted');
$('span', background).eq(position).addClass('highlighted');
};
loop.startLoop();
}
function updateSequence(name, value){
loop.tracks[name].loop = value;
}
function wrapInSpans(text){
text = text.split('').join('</span><span>');
var result = '<span>'+text+'</span>';
result.replace(' ', ' ');
return result;
}
$(function () {
initLoop();
$('.sequence').each(function(){
var sequence = $(this).data('sequence');
var value = loop.tracks[sequence].loop.join('');
value = wrapInSpans(value);
$(this).prev('.sequenceBackground').html(value);
$(this).html(value);
});
$('.sequence').keyup(function(e){
var sequence = $(this).data('sequence');
loop.tracks[sequence].loop = $(this).text().split('');
var value = $(this).text();
//value = $.trim(value);
value = wrapInSpans(value);
$(this).prev('.sequenceBackground').html(value).show();
e.originalEvent.keyCode = 80;
});
$('.sequence').keydown(function(){
$(this).prev('.sequenceBackground').hide();
});
});
</script>
<style type='text/css'>
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,400,600);
body {
font-family: 'Open Sans', sans-serif;
}
.center {
position: absolute;
top: 50%;
left: 0;
height: 200px;
width: 100%;
margin-top: -100px;
}
.sequenceContainer {
position: relative;
height: 50px;
}
.sequence, .sequenceBackground {
display: block;
font-weight: 600;
width: 100%;
position: absolute;
top: 0;
left: 0;
text-align: center;
font-size: 40px;
border: 0 none;
outline: none;
background: transparent;
opacity: 0.5;
-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
}
.highlighted {
opacity: 1.0;
font-size: 40px;
text-shadow: 0px 0px 10px blue;
color: blue;
}
</style>
</head>
<body>
<div class='center'>
<div class='sequenceContainer'>
<div class='sequenceBackground' data-sequence='drum'></div>
<div class='sequence' data-sequence='drum' type='text' contenteditable='true'></div>
</div>
<div class='sequenceContainer'>
<div class='sequenceBackground' data-sequence='hihat'></div>
<div class='sequence' data-sequence='hihat' type='text' contenteditable='true'></div>
</div>
</div>
</body>
</html>