Telegraph sounds, implements #22

This commit is contained in:
Neale Pickett 2022-04-21 18:31:33 -06:00
parent 1229fa940d
commit 10e869f946
3 changed files with 68 additions and 17 deletions

View File

@ -251,6 +251,12 @@
max="9999" max="9999"
value="4000"> value="4000">
</p> </p>
<p>
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="telegraph-buzzer">
<input type="checkbox" id="telegraph-buzzer" class="mdl-switch__input">
<span class="mdl-switch__label">Telegraph sounds</span>
</label>
</p>
<hr> <hr>
<table> <table>
<tbody> <tbody>

View File

@ -494,5 +494,41 @@ class Buzzer {
} }
} }
class TelegraphBuzzer extends Buzzer{
constructor(gain=0.6) {
super()
this.gain = this.ac.createGain()
this.gain.connect(this.ac.destination)
this.gain.gain.value = gain
this.loadMedia("telegraph-a.mp3").then(s => this.closeBuf = s)
this.loadMedia("telegraph-b.mp3").then(s => this.openBuf = s)
}
async loadMedia(url) {
let resp = await fetch(url)
let buf = await resp.arrayBuffer()
return await this.ac.decodeAudioData(buf)
}
play(buf, when) {
let bs = this.ac.createBufferSource()
bs.buffer = buf
bs.connect(this.gain)
bs.start(this.acTime(when))
}
Buzz(tx, when=0) {
if (tx) return
this.play(this.closeBuf, when)
}
Silence(tx ,when=0) {
if (tx) return
this.play(this.openBuf, when)
}
}
export {DIT, DAH, PAUSE, PAUSE_WORD, PAUSE_LETTER} export {DIT, DAH, PAUSE, PAUSE_WORD, PAUSE_LETTER}
export {Keyer, Buzzer} export {Keyer, Buzzer, TelegraphBuzzer}

View File

@ -34,15 +34,6 @@ class VailClient {
this.beginTxTime = null // Time when we began transmitting this.beginTxTime = null // Time when we began transmitting
this.debug = localStorage.debug this.debug = localStorage.debug
// Redirect old URLs
if (window.location.search) {
let me = new URL(location)
let repeater = me.searchParams.get("repeater")
me.search = ""
me.hash = decodeURIComponent(repeater)
window.location = me
}
// Make helpers // Make helpers
this.buzzer = new Morse.Buzzer() this.buzzer = new Morse.Buzzer()
this.keyer = new Morse.Keyer(() => this.beginTx(), () => this.endTx()) this.keyer = new Morse.Keyer(() => this.beginTx(), () => this.endTx())
@ -78,13 +69,29 @@ class VailClient {
this.inputInit("#iambic-typeahead", e => { this.inputInit("#iambic-typeahead", e => {
this.keyer.SetTypeahead(e.target.checked) this.keyer.SetTypeahead(e.target.checked)
}) })
this.inputInit("#telegraph-buzzer", e => {
this.setTelegraphBuzzer(e.target.checked)
})
// Fill in the name of our repeater // Fill in the name of our repeater
let repeaterElement = document.querySelector("#repeater").addEventListener("change", e => this.setRepeater(e.target.value.trim())) document.querySelector("#repeater").addEventListener("change", e => this.setRepeater(e.target.value.trim()))
window.addEventListener("hashchange", () => this.hashchange()) window.addEventListener("hashchange", () => this.hashchange())
this.hashchange() this.hashchange()
} }
/**
* Toggle the clicktastic buzzer, instead of the beeptastic one.
*
* @param {bool} enable true to enable clicky buzzer
*/
setTelegraphBuzzer(enable) {
if (enable) {
this.buzzer = new Morse.TelegraphBuzzer()
} else {
this.buzzer = new Morse.Buzzer()
}
}
/** /**
* Called when the hash part of the URL has changed. * Called when the hash part of the URL has changed.
*/ */
@ -185,7 +192,7 @@ class VailClient {
let storedValue = localStorage[element.id] let storedValue = localStorage[element.id]
if (storedValue != null) { if (storedValue != null) {
element.value = storedValue element.value = storedValue
element.checked = JSON.parse(storedValue) element.checked = (storedValue == "on")
} }
let outputElement = document.querySelector(selector + "-value") let outputElement = document.querySelector(selector + "-value")
let outputWpmElement = document.querySelector(selector + "-wpm") let outputWpmElement = document.querySelector(selector + "-wpm")
@ -194,9 +201,11 @@ class VailClient {
let value = element.value let value = element.value
if (element.hasAttribute("checked")) { if (element.hasAttribute("checked")) {
value = element.checked value = element.checked
localStorage[element.id] = value?"on":"off"
} else {
localStorage[element.id] = value
} }
localStorage[element.id] = value
if (outputElement) { if (outputElement) {
outputElement.value = value outputElement.value = value
} }