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

Create README.md #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
Sound Looper
18 changes: 15 additions & 3 deletions web/index.html
@@ -1,15 +1,25 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Sound Looper</title>
<script src="index.js" defer></script>
<style>
html, body {
html,
body {
-webkit-user-select: none;
/* Safari */
-moz-user-select: none;
/* Firefox */
-ms-user-select: none;
/* IE10+/Edge */
user-select: none;
/* Standard */
}

#drums, #guitar {
#drums,
#guitar {
border: 1px solid black;
width: 100px;
height: 100px;
Expand All @@ -21,11 +31,13 @@
}
</style>
</head>

<body>
<button id="play">Play</button>
<div style="display: flex">
<div id="drums"></div>
<div id="guitar"></div>
</div>
</body>

</html>
32 changes: 23 additions & 9 deletions web/index.js
Expand Up @@ -8,9 +8,10 @@ let guitarEnabled = true;
let guitarSource = null;
let drumSource = null;
let drumGainNode = null;
let guitarGainNode = null; // Added gain node for guitar
let guitarGainNode = null;

async function run() {
try {
const audioContext = new AudioContext();

const drumLoopResponse = await fetch("/drum-loop.mp3");
Expand Down Expand Up @@ -40,35 +41,48 @@ async function run() {
guitarGainNode.gain.value = 0;
guitarSource.connect(guitarGainNode);
guitarGainNode.connect(audioContext.destination); // Connect gain node to destination
} catch(err) {
alert(err.message);
}
}

drumsBtn.addEventListener("mousedown", (e) => {
function activateDrums(e) {
e.preventDefault();
drumsEnabled = true;
drumGainNode.gain.value = 1;
toggleButtonColor(drumsBtn, drumsEnabled);
});
}

drumsBtn.addEventListener("mouseup", (e) => {
function deactivateDrums(e) {
e.preventDefault();
drumsEnabled = false;
drumGainNode.gain.value = 0;
toggleButtonColor(drumsBtn, drumsEnabled);
});
}

guitarBtn.addEventListener("mousedown", (e) => {
function activateGuitar(e) {
e.preventDefault();
guitarEnabled = true;
guitarGainNode.gain.value = 1;
toggleButtonColor(guitarBtn, guitarEnabled);
});
}

guitarBtn.addEventListener("mouseup", (e) => {
function deactivateGuitar(e) {
e.preventDefault();
guitarEnabled = false;
guitarGainNode.gain.value = 0;
toggleButtonColor(guitarBtn, guitarEnabled);
});
}

drumsBtn.addEventListener("mousedown", activateDrums);
drumsBtn.addEventListener("touchstart", activateDrums);
drumsBtn.addEventListener("mouseup", deactivateDrums);
drumsBtn.addEventListener("touchend", deactivateDrums);

guitarBtn.addEventListener("mousedown", activateGuitar);
guitarBtn.addEventListener("touchstart", activateGuitar);
guitarBtn.addEventListener("mouseup", deactivateGuitar);
guitarBtn.addEventListener("touchend", deactivateGuitar);

playBtn.addEventListener("click", async () => {
try {
Expand Down