Skip to content

Commit 241b987

Browse files
committed
Volume control is added
1 parent 8652912 commit 241b987

5 files changed

Lines changed: 31 additions & 7 deletions

File tree

app/css/style.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ main {
9292
display: grid;
9393
grid-template-columns: 1fr;
9494
grid-template-rows: 0 auto 1fr 3.875rem auto;
95-
transition: grid-template-rows 300ms;
95+
transition: grid-template-rows 150ms;
9696

9797
position: relative;
9898

@@ -111,7 +111,7 @@ main {
111111
}
112112

113113
&.settings-open {
114-
grid-template-rows: 3.5rem auto 1fr 3.875rem auto;
114+
grid-template-rows: 9rem auto 1fr 3.875rem auto;
115115
}
116116
}
117117

@@ -150,7 +150,7 @@ h1 {
150150
flex-direction: column;
151151
overflow: hidden;
152152

153-
.words-per-minute {
153+
.words-per-minute, .volume {
154154
display: grid;
155155
row-gap: 0.5rem;
156156
column-gap: 1rem;
@@ -173,6 +173,10 @@ h1 {
173173
text-align: right;
174174
}
175175
}
176+
177+
.volume {
178+
margin-top: 1rem;
179+
}
176180
}
177181

178182
input[type="range"]::-webkit-slider-runnable-track {
@@ -581,7 +585,7 @@ button.signal-on {
581585
}
582586

583587
&.settings-open {
584-
grid-template-rows: 3.5rem auto 1fr auto;
588+
grid-template-rows: 9rem auto 1fr auto;
585589
}
586590
}
587591
}

app/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<input type="range" name="words-per-minute" min="3" max="15" class="words-per-minute" />
3232
<span class="value"></span>
3333
</div>
34+
<div class="volume">
35+
<label for="volume">Volume</label>
36+
<input type="range" name="volume" min="0" max="100" value="50" />
37+
<span class="value">50%</span>
38+
</div>
3439
</div>
3540

3641
<h1>International <span class="no-wrap">Morse Decoder</span></h1>

app/script/audio.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const audioCtx = new (window.AudioContext || window.webkitAudioContext)()
22

3+
const gainNode = audioCtx.createGain()
4+
gainNode.connect(audioCtx.destination)
5+
gainNode.gain.value = 0.5
6+
37
function isAudioSuspended() {
48
return audioCtx.state === 'suspended'
59
}
@@ -14,8 +18,7 @@ function createOscillator() {
1418
const currentTime = audioCtx.currentTime
1519
oscillator.frequency.setValueAtTime(frequency, currentTime)
1620

17-
const destination = audioCtx.destination
18-
oscillator.connect(destination)
21+
oscillator.connect(gainNode)
1922

2023
return oscillator
2124
}
@@ -43,3 +46,7 @@ function stopBeep() {
4346
morseOscillator.disconnect()
4447
morseOscillator = null
4548
}
49+
50+
function setVolume(value) {
51+
gainNode.gain.value = value / 100
52+
}

app/script/morse.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script/visualizer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ function addSettingsListeners(morseEncoder, wordsPerMinute) {
2929
morseEncoder.setWordsPerMinute(wordsPerMinute)
3030
wordsPerMinuteValue.textContent = wordsPerMinute
3131
})
32+
33+
const volumeValue = document.querySelector(".volume .value")
34+
const volumeInput = document.querySelector(".volume input")
35+
volumeInput.addEventListener('input', (e) => {
36+
const volume = parseInt(e.target.value)
37+
setVolume(volume)
38+
volumeValue.textContent = volume + '%'
39+
})
3240
}
3341

3442
function addSignalButtonListener(morseEncoder) {

0 commit comments

Comments
 (0)