Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "sound codes" #26

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<script src="./js/sm2/js/soundmanager2-jsmin.js"></script>
<script src="./js/core.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120277085-2"></script>
<button id="playButton">Play Mucic Code</button>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
Expand Down Expand Up @@ -94,6 +95,22 @@
<div class="tap" id="meow">
<span>SPACE</span>
</div>
<div id="codeModal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<p>Imput Code Below:</p>
<textarea rows="15" cols="100" placeholder="Input Code Here" id=code></textarea>
<button id="spaceClear">Clear Spaces</button><br>
<input type="text" id="timing" size="23" placeholder="Time between notes (ms)"></textarea>
<button id="submitButton">Play Code</button>
</div>
</div>
<div id="playModal" class="modal">
<div class="modal-content">
<p><font size="25">You Have Recived A Song!</font></p>
<button id="playCode">Play!</button>
</div>
</div>
<img src="./images/l2.png" class="hidden"/>
<img src="./images/r2.png" class="hidden"/>
<img src="./images/m2.png" class="hidden"/>
Expand Down
52 changes: 52 additions & 0 deletions js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,55 @@ $(document).on("keydown keyup", function (e) {
$.play(instrument, key, e.type === "keydown");
}
});
$(document).ready(function() {
document.getElementById("playButton").addEventListener("click", function() {
document.getElementById("codeModal").style.display = "block";
});
document.getElementsByClassName("close")[0].addEventListener("click", function() {
document.getElementById("codeModal").style.display = "none";
});
document.getElementById("spaceClear").addEventListener("click", function() {
var code = document.getElementById("code").value;
var newCode = code.replace(/ /g,'');
document.getElementById("code").value = newCode;
});
document.getElementById("submitButton").addEventListener("click", function() {
document.getElementById("codeModal").style.display = "none";
var code = document.getElementById("code").value;
var timing = parseInt(document.getElementById("timing").value);
playCode(code, timing);
});
});
$(document).ready(function() {
var url_string = window.location.href;
var url = new URLSearchParams(url_string);
var c = url.get("c");
var t = url.get("t");
console.log("Code: " + c + " Timing: " + t);
if(c != null && t != null) {
document.getElementById("playModal").style.display = "block";
document.getElementById("playCode").addEventListener("click", function() {
document.getElementById("playModal").style.display = "none";
playCode(c, t);
});
}
});
function playCode(code, timing) {
var length = code.length;
var index = 0;
var timer = setInterval(function() {
index++;
var instrument = InstrumentPerKeyEnum[code.charAt(index-1).toUpperCase()];
var key = KeyEnum[code.charAt(index-1).toUpperCase()];
if(instrument != undefined && key != undefined) {
$.play(instrument, key, true);
setTimeout(function() {
$.play(instrument, key, false);
}, timing/2)
}
if(index >= length) {
clearInterval(timer);
index = 0;
}
}, timing );
}
35 changes: 35 additions & 0 deletions style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,41 @@ a {
margin: 2px;
display: inline-block;
}
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
#code {
resize: none;
}
#bongo-left {
top: 43%;
left: 2%;
Expand Down