Skip to content

Commit effdabd

Browse files
author
devbyali
committed
adding tempo
1 parent 705de00 commit effdabd

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

app.js

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class DrumKit {
1313
this.isPlaying = null;
1414
this.selects = document.querySelectorAll("select");
1515
this.muteBtn = document.querySelectorAll(".mute");
16+
this.tempoSlider = document.querySelector(".tempo-slider");
1617
}
1718
activePad() {
1819
this.classList.toggle("active");
@@ -111,6 +112,19 @@ class DrumKit {
111112
}
112113
}
113114
}
115+
changeTempo(e) {
116+
const tempoText = document.querySelector(".tempo-nr");
117+
tempoText.innerText = e.target.value;
118+
}
119+
updateTempo(e) {
120+
this.bpm = e.target.value;
121+
clearInterval(this.isPlaying);
122+
this.isPlaying = null;
123+
const playBtn = document.querySelector(".play");
124+
if (playBtn.classList.contains("active")) {
125+
this.start();
126+
}
127+
}
114128
}
115129
const drumKit = new DrumKit();
116130

@@ -136,3 +150,9 @@ drumKit.muteBtn.forEach((btn) => {
136150
drumKit.mute(e);
137151
});
138152
});
153+
drumKit.tempoSlider.addEventListener("input", (e) => {
154+
drumKit.changeTempo(e);
155+
});
156+
drumKit.tempoSlider.addEventListener("change", (e) => {
157+
drumKit.updateTempo(e);
158+
});

index.html

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ <h1>HiHat</h1>
8181
</div>
8282
</div>
8383
<button class="play">Play</button>
84+
<div class="tempo">
85+
<input type="range" class="tempo-slider" max="100" min="0" value="50">
86+
<p>Tempo: <span class="tempo-nr">50</span></p>
87+
</div>
8488
</div>
8589
<audio class="kick-sound" src="./sounds/kick-classic.wav"></audio>
8690
<audio class="snare-sound" src="./sounds/snare-acoustic01.wav"></audio>

style.css

+27-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ svg {
2020
height: 5rem;
2121
margin: 1rem 0.5rem;
2222
cursor: pointer;
23+
border-radius: 3px;
2324
}
2425

2526
.kick-pad {
@@ -61,7 +62,7 @@ svg {
6162
align-items: center;
6263
width: 70%;
6364
justify-content: space-between;
64-
margin-top: 5rem;
65+
margin-top: 2rem;
6566
}
6667

6768
.kick,
@@ -102,7 +103,7 @@ svg {
102103
border: none;
103104
cursor: pointer;
104105
margin-top: 3rem;
105-
border-radius: 3px;
106+
border-radius: 1rem;
106107
}
107108

108109
select {
@@ -115,6 +116,30 @@ select {
115116
color: white;
116117
}
117118

119+
.tempo {
120+
margin: 3rem;
121+
width: 30%;
122+
}
123+
124+
.tempo-slider {
125+
padding: 0.1rem;
126+
-webkit-appearance: none;
127+
margin: 1rem 0;
128+
width: 100%;
129+
position: relative;
130+
background: rgb(88, 88, 88);
131+
border-radius: 1rem;
132+
border: none;
133+
outline: none;
134+
cursor: pointer;
135+
}
136+
137+
.tempo p {
138+
font-size: 1.5rem;
139+
margin: 0.5rem;
140+
text-align: center;
141+
}
142+
118143
@keyframes playTrack {
119144
from {
120145
transform: scale(1);

0 commit comments

Comments
 (0)