A Pen by Matt Porter on CodePen.
Created
August 26, 2014 13:26
-
-
Save M-Porter/2a3c5a2bbb933c89f22e to your computer and use it in GitHub Desktop.
A Pen by Matt Porter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'> | |
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css"/> | |
<div id="outter"> | |
<div id="inner"> | |
<div id="launcher"> | |
<div id="title">BeatStudio <span class="red">9</span><span class="yellow">0</span><span class="blue">0</span><span class="purple">0</span></div> | |
<div id="countRow"> | |
<li class="numbers red">1</li> | |
<li class="numbers red">2</li> | |
<li class="numbers red">3</li> | |
<li class="numbers red">4</li> | |
<li class="numbers yellow">5</li> | |
<li class="numbers yellow">6</li> | |
<li class="numbers yellow">7</li> | |
<li class="numbers yellow">8</li> | |
<li class="numbers blue">9</li> | |
<li class="numbers blue">10</li> | |
<li class="numbers blue">11</li> | |
<li class="numbers blue">12</li> | |
<li class="numbers purple">13</li> | |
<li class="numbers purple">14</li> | |
<li class="numbers purple">15</li> | |
<li class="numbers purple">16</li> | |
</div> | |
<div id="kickRow"> | |
<li class="kickBlockON" id="clip" name="1" onclick="player.update(1,1);"></li> | |
<li class="kickBlockOFF" id="clip" name="2" onclick="player.update(1,2);"></li> | |
<li class="kickBlockON" id="clip" name="3" onclick="player.update(1,3);"></li> | |
<li class="kickBlockOFF" id="clip" name="4" onclick="player.update(1,4);"></li> | |
<li class="kickBlockOFF" id="clip" name="5" onclick="player.update(1,5);"></li> | |
<li class="kickBlockOFF" id="clip" name="6" onclick="player.update(1,6);"></li> | |
<li class="kickBlockON" id="clip" name="7" onclick="player.update(1,7);"></li> | |
<li class="kickBlockOFF" id="clip" name="8" onclick="player.update(1,8);"></li> | |
<li class="kickBlockOFF" id="clip" name="9" onclick="player.update(1,9);"></li> | |
<li class="kickBlockOFF" id="clip" name="10" onclick="player.update(1,10);"></li> | |
<li class="kickBlockON" id="clip" name="11" onclick="player.update(1,11);"></li> | |
<li class="kickBlockOFF" id="clip" name="12" onclick="player.update(1,12);"></li> | |
<li class="kickBlockOFF" id="clip" name="13" onclick="player.update(1,13);"></li> | |
<li class="kickBlockOFF" id="clip" name="14" onclick="player.update(1,14);"></li> | |
<li class="kickBlockON" id="clip" name="15" onclick="player.update(1,15);"></li> | |
<li class="kickBlockOFF" id="clip" name="16" onclick="player.update(1,16);"></li> | |
</div> | |
<div id="snareRow"> | |
<li class="snareBlockOFF" id="clip" name="1" onclick="player.update(2,1);"></li> | |
<li class="snareBlockOFF" id="clip" name="2" onclick="player.update(2,2);"></li> | |
<li class="snareBlockOFF" id="clip" name="3" onclick="player.update(2,3);"></li> | |
<li class="snareBlockOFF" id="clip" name="4" onclick="player.update(2,4);"></li> | |
<li class="snareBlockON" id="clip" name="5" onclick="player.update(2,5);"></li> | |
<li class="snareBlockOFF" id="clip" name="6" onclick="player.update(2,6);"></li> | |
<li class="snareBlockOFF" id="clip" name="7" onclick="player.update(2,7);"></li> | |
<li class="snareBlockOFF" id="clip" name="8" onclick="player.update(2,8);"></li> | |
<li class="snareBlockOFF" id="clip" name="9" onclick="player.update(2,9);"></li> | |
<li class="snareBlockOFF" id="clip" name="10" onclick="player.update(2,10);"></li> | |
<li class="snareBlockOFF" id="clip" name="11" onclick="player.update(2,11);"></li> | |
<li class="snareBlockOFF" id="clip" name="12" onclick="player.update(2,12);"></li> | |
<li class="snareBlockON" id="clip" name="13" onclick="player.update(2,13);"></li> | |
<li class="snareBlockOFF" id="clip" name="14" onclick="player.update(2,14);"></li> | |
<li class="snareBlockOFF" id="clip" name="15" onclick="player.update(2,15);"></li> | |
<li class="snareBlockOFF" id="clip" name="16" onclick="player.update(2,16);"></li> | |
</div> | |
<div id="clapRow"> | |
<li class="clapBlockOFF" id="clip" name="1" onclick="player.update(3,1);"></li> | |
<li class="clapBlockOFF" id="clip" name="2" onclick="player.update(3,2);"></li> | |
<li class="clapBlockOFF" id="clip" name="3" onclick="player.update(3,3);"></li> | |
<li class="clapBlockOFF" id="clip" name="4" onclick="player.update(3,4);"></li> | |
<li class="clapBlockON" id="clip" name="5" onclick="player.update(3,5);"></li> | |
<li class="clapBlockOFF" id="clip" name="6" onclick="player.update(3,6);"></li> | |
<li class="clapBlockOFF" id="clip" name="7" onclick="player.update(3,7);"></li> | |
<li class="clapBlockOFF" id="clip" name="8" onclick="player.update(3,8);"></li> | |
<li class="clapBlockOFF" id="clip" name="9" onclick="player.update(3,9);"></li> | |
<li class="clapBlockOFF" id="clip" name="10" onclick="player.update(3,10);"></li> | |
<li class="clapBlockOFF" id="clip" name="11" onclick="player.update(3,11);"></li> | |
<li class="clapBlockOFF" id="clip" name="12" onclick="player.update(3,12);"></li> | |
<li class="clapBlockON" id="clip" name="13" onclick="player.update(3,13);"></li> | |
<li class="clapBlockOFF" id="clip" name="14" onclick="player.update(3,14);"></li> | |
<li class="clapBlockOFF" id="clip" name="15" onclick="player.update(3,15);"></li> | |
<li class="clapBlockOFF" id="clip" name="16" onclick="player.update(3,16);"></li> | |
</div> | |
<div id="hatRow"> | |
<li class="hatBlockON" id="clip" name="1" onclick="player.update(4,1);"></li> | |
<li class="hatBlockON" id="clip" name="2" onclick="player.update(4,2);"></li> | |
<li class="hatBlockON" id="clip" name="3" onclick="player.update(4,3);"></li> | |
<li class="hatBlockON" id="clip" name="4" onclick="player.update(4,4);"></li> | |
<li class="hatBlockON" id="clip" name="5" onclick="player.update(4,5);"></li> | |
<li class="hatBlockON" id="clip" name="6" onclick="player.update(4,6);"></li> | |
<li class="hatBlockON" id="clip" name="7" onclick="player.update(4,7);"></li> | |
<li class="hatBlockON" id="clip" name="8" onclick="player.update(4,8);"></li> | |
<li class="hatBlockON" id="clip" name="9" onclick="player.update(4,9);"></li> | |
<li class="hatBlockON" id="clip" name="10" onclick="player.update(4,10);"></li> | |
<li class="hatBlockON" id="clip" name="11" onclick="player.update(4,11);"></li> | |
<li class="hatBlockON" id="clip" name="12" onclick="player.update(4,12);"></li> | |
<li class="hatBlockON" id="clip" name="13" onclick="player.update(4,13);"></li> | |
<li class="hatBlockON" id="clip" name="14" onclick="player.update(4,14);"></li> | |
<li class="hatBlockON" id="clip" name="15" onclick="player.update(4,15);"></li> | |
<li class="hatBlockON" id="clip" name="16" onclick="player.update(4,16);"></li> | |
</div> | |
<div id="actionRow"> | |
<div id="playButton"> | |
Play | |
</div> | |
</div> | |
</div> | |
<div class="footer"> | |
The MIT License (MIT) -- Copyright (c) 2013 Matthew Porter | |
</div> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Made a custom little Beat Studio for you guys to mess around on. | |
// Took me forever to make so please dont steal it :) | |
// | |
// As always, MIT license. Enjoy! | |
// | |
/* | |
The MIT License (MIT) | |
Copyright (c) 2013 Matthew Porter | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
$('li').each( function(index) { | |
$(this).click( function(event) { | |
var kick = new Audio('http://www.personal.psu.edu/mtp5129/audio/kick.wav'), | |
clap = new Audio('http://www.personal.psu.edu/mtp5129/audio/clap.wav'), | |
hat = new Audio('http://www.personal.psu.edu/mtp5129/audio/hat.wav'), | |
snare = new Audio('http://www.personal.psu.edu/mtp5129/audio/snare.wav'); | |
var target = $(event.target); | |
if(target.attr('class') == 'kickBlockOFF') { | |
target.attr('class', 'kickBlockON'); | |
kick.play(); | |
} else if(target.attr('class') == 'kickBlockON') { | |
target.attr('class','kickBlockOFF'); | |
} | |
if(target.attr('class') == 'snareBlockOFF') { | |
target.attr('class','snareBlockON'); | |
snare.play(); | |
} else if(target.attr('class') == 'snareBlockON') { | |
target.attr('class','snareBlockOFF'); | |
} | |
if(target.attr('class') == 'hatBlockOFF') { | |
target.attr('class','hatBlockON'); | |
hat.play(); | |
} else if(target.attr('class') == 'hatBlockON') { | |
target.attr('class','hatBlockOFF'); | |
} | |
if(target.attr('class') == 'clapBlockOFF') { | |
target.attr('class','clapBlockON'); | |
clap.play(); | |
} else if(target.attr('class') == 'clapBlockON') { | |
target.attr('class','clapBlockOFF'); | |
} | |
}); | |
}); | |
function rk(i) { | |
if(i==1) { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/kick.wav'); | |
} else { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/blank.wav'); | |
} | |
} | |
function rs(i) { | |
if(i==1) { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/snare.wav'); | |
} else { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/blank.wav'); | |
} | |
} | |
function rc(i) { | |
if(i==1) { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/clap.wav'); | |
} else { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/blank.wav'); | |
} | |
} | |
function rh(i) { | |
if(i==1) { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/hat.wav'); | |
} else { | |
return new Audio('http://www.personal.psu.edu/mtp5129/audio/blank.wav'); | |
} | |
} | |
function BeatStudio(opts) { | |
this.kArr = new Array(1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0); | |
this.sArr = new Array(0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0); | |
this.cArr = new Array(0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0); | |
this.hArr = new Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); | |
this.bpm = opts.bpm; | |
this.timeout = ((1/this.bpm)*60000)/2; | |
} | |
BeatStudio.prototype = { | |
update: function(row, beat) { | |
var type = row; | |
var i = beat-1; | |
if(type==1) { | |
if(this.kArr[i] == 1) { | |
this.kArr[i] = 0; | |
} else { | |
this.kArr[i] = 1; | |
} | |
} | |
if(type==2) { | |
if(this.sArr[i] == 1) { | |
this.sArr[i] = 0; | |
} else { | |
this.sArr[i] = 1; | |
} | |
} | |
if(type==3) { | |
if(this.cArr[i] == 1) { | |
this.cArr[i] = 0; | |
} else { | |
this.cArr[i] = 1; | |
} | |
} | |
if(type==4) { | |
if(this.hArr[i] == 1) { | |
this.hArr[i] = 0; | |
} else { | |
this.hArr[i] = 1; | |
} | |
} | |
}, | |
launch: function() { | |
var kickTmp = this.kArr; | |
var snareTmp = this.sArr; | |
var clapTmp = this.cArr; | |
var hatTmp = this.hArr; | |
var timeout = this.timeout; | |
// handles the actual beat below | |
setTimeout(function(){ | |
rk(kickTmp[0]).play(); | |
rs(snareTmp[0]).play(); | |
rc(clapTmp[0]).play(); | |
rh(hatTmp[0]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[1]).play(); | |
rs(snareTmp[1]).play(); | |
rc(clapTmp[1]).play(); | |
rh(hatTmp[1]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[2]).play(); | |
rs(snareTmp[2]).play(); | |
rc(clapTmp[2]).play(); | |
rh(hatTmp[2]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[3]).play(); | |
rs(snareTmp[3]).play(); | |
rc(clapTmp[3]).play(); | |
rh(hatTmp[3]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[4]).play(); | |
rs(snareTmp[4]).play(); | |
rc(clapTmp[4]).play(); | |
rh(hatTmp[4]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[5]).play(); | |
rs(snareTmp[5]).play(); | |
rc(clapTmp[5]).play(); | |
rh(hatTmp[5]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[6]).play(); | |
rs(snareTmp[6]).play(); | |
rc(clapTmp[6]).play(); | |
rh(hatTmp[6]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[7]).play(); | |
rs(snareTmp[7]).play(); | |
rc(clapTmp[7]).play(); | |
rh(hatTmp[7]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[8]).play(); | |
rs(snareTmp[8]).play(); | |
rc(clapTmp[8]).play(); | |
rh(hatTmp[8]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[9]).play(); | |
rs(snareTmp[9]).play(); | |
rc(clapTmp[9]).play(); | |
rh(hatTmp[9]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[10]).play(); | |
rs(snareTmp[10]).play(); | |
rc(clapTmp[10]).play(); | |
rh(hatTmp[10]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[11]).play(); | |
rs(snareTmp[11]).play(); | |
rc(clapTmp[11]).play(); | |
rh(hatTmp[11]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[12]).play(); | |
rs(snareTmp[12]).play(); | |
rc(clapTmp[12]).play(); | |
rh(hatTmp[12]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[13]).play(); | |
rs(snareTmp[13]).play(); | |
rc(clapTmp[13]).play(); | |
rh(hatTmp[13]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[14]).play(); | |
rs(snareTmp[14]).play(); | |
rc(clapTmp[14]).play(); | |
rh(hatTmp[14]).play(); | |
setTimeout(function(){ | |
rk(kickTmp[15]).play(); | |
rs(snareTmp[15]).play(); | |
rc(clapTmp[15]).play(); | |
rh(hatTmp[15]).play(); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, timeout); | |
}, 0); | |
}, | |
}; | |
// Initiate new BeatStudio | |
var player = new BeatStudio({bpm: 140}); | |
document.getElementById('playButton').addEventListener('click', function() { | |
player.launch(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background: #666666; | |
-webkit-touch-callout: none; | |
-webkit-user-select: none; | |
-khtml-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
outline-style:none;/*IE*/ | |
} | |
#outter { | |
position: relative; | |
display:inline-block; | |
left: 50%; | |
} | |
#inner { | |
position: relative; | |
left: -50%; | |
} | |
#launcher { | |
padding: 16px; | |
background: #2d2d2d; | |
margin: 50px 0; | |
border: 1px solid rgba(1,1,1,0.35); | |
box-shadow: 0 0 40px rgba(1,1,1,0.40), | |
0 0 15px rgba(1,1,1,0.10); | |
} | |
.red { | |
color: #f2777a; | |
} | |
.yellow { | |
color: #ffcc66; | |
} | |
.blue { | |
color: #66cccc; | |
} | |
.purple { | |
color: #cc99cc; | |
} | |
#title { | |
font-size: 36px; | |
font-family: 'Lobster'; | |
color: #f0f0f0; | |
text-shadow: 0 -1px 0 #000000, | |
0 -2px 0 #000000, | |
0 -2px 10px rgba(1,1,1,0.25); | |
text-align: right; | |
line-height: 48px; | |
vertical-align: middle; | |
} | |
#actionRow { | |
padding: 16px 0 0 0; | |
height: 36px; | |
display: block; | |
} | |
#playButton { | |
display: inline; | |
line-height: 36px; | |
text-align: center; | |
vertical-align: middle; | |
font-size: 24px; | |
color: #f0f0f0; | |
font-family: 'Open Sans'; | |
background: #f2777a; | |
box-shadow: 0 -1px 0 #000000, | |
0 -2px 0 #000000, | |
0 -2px 10px rgba(1,1,1,0.25); | |
float: right; | |
padding: 0 36px; | |
outline: none; | |
-webkit-animation-name: colors; | |
-webkit-animation-iteration-count: infinite; | |
-webkit-animation-timing-function: linear; | |
-webkit-animation-duration: 10s; | |
} | |
@-webkit-keyframes colors { | |
25% { | |
background: #ffcc66; | |
} | |
50% { | |
background: #66cccc; | |
} | |
75% { | |
background: #cc99cc; | |
} | |
} | |
#countRow { | |
display: block; | |
color: #f0f0f0; | |
} | |
#countRow .numbers{ | |
width: 36px; | |
line-height: 26px; | |
font-size: 14px; | |
font-family: 'Open Sans'; | |
text-shadow: 0 -1px 0 rgba(1,1,1,1), | |
0 -2px 0 rgba(1,1,1,1); | |
text-align: center; | |
display: inline-block; | |
} | |
#kickRow { | |
display: block; | |
} | |
#kickRow .kickBlockON { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #f2777a; | |
} | |
#kickRow .kickBlockOFF { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #d2d2d2; | |
} | |
#kickRow .kickBlockOFF:hover { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #f2777a; | |
} | |
#snareRow { | |
display: block; | |
} | |
#snareRow .snareBlockON { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #ffcc66; | |
} | |
#snareRow .snareBlockOFF:hover { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #ffcc66; | |
} | |
#snareRow .snareBlockOFF { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #d2d2d2; | |
} | |
#clapRow { | |
display: block; | |
} | |
#clapRow .clapBlockON { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #66cccc; | |
} | |
#clapRow .clapBlockOFF { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #d2d2d2; | |
} | |
#clapRow .clapBlockOFF:hover { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #66cccc; | |
} | |
#hatRow { | |
display: block; | |
} | |
#hatRow .hatBlockON { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #cc99cc; | |
} | |
#hatRow .hatBlockOFF { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #d2d2d2; | |
} | |
#hatRow .hatBlockOFF:hover { | |
display: inline-block; | |
width: 36px; | |
height: 36px; | |
background: #cc99cc; | |
} | |
.footer { | |
font-family: 'Open Sans'; | |
font-size: 12px; | |
color: #2d2d2d; | |
text-align: center; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment