mirror of https://github.com/nealey/vail.git
Add frequency display
This commit is contained in:
parent
4bdb707730
commit
0dffcbfab0
|
@ -213,7 +213,7 @@
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label">
|
<div class="field-label">
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span data-i18n="label.rx-delay">rx delay:</span>
|
<span data-i18n="label.rx-delay">rx delay</span>:
|
||||||
<output for="rx-delay"></output>s
|
<output for="rx-delay"></output>s
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -249,7 +249,7 @@
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label">
|
<div class="field-label">
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span data-i18n="label.gain">volume:</span>
|
<span data-i18n="label.gain">volume</span>:
|
||||||
<output for="masterGain"></output>%
|
<output for="masterGain"></output>%
|
||||||
<i class="mdi mdi-volume-off muted"></i>
|
<i class="mdi mdi-volume-off muted"></i>
|
||||||
</label>
|
</label>
|
||||||
|
@ -272,8 +272,9 @@
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label">
|
<div class="field-label">
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span data-i18n="label.tx-tone">tx tone:</span>
|
<span data-i18n="label.tx-tone">tx tone</span>:
|
||||||
<output for="tx-tone"></output>
|
<output for="tx-tone" data-transform="note"></output>
|
||||||
|
<output for="tx-tone" data-transform="freq"></output>Hz
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-body">
|
<div class="field-body">
|
||||||
|
@ -295,8 +296,9 @@
|
||||||
<div class="field is-horizontal">
|
<div class="field is-horizontal">
|
||||||
<div class="field-label">
|
<div class="field-label">
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span data-i18n="label.rx-tone">rx tone:</span>
|
<span data-i18n="label.rx-tone">rx tone</span>:
|
||||||
<output for="rx-tone"></output>
|
<output for="rx-tone" data-transform="note"></output>
|
||||||
|
<output for="rx-tone" data-transform="freq"></output>Hz
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-body">
|
<div class="field-body">
|
||||||
|
|
|
@ -31,8 +31,9 @@ const note_names = [
|
||||||
* @param {Number} note MIDI note number
|
* @param {Number} note MIDI note number
|
||||||
* @returns {Number} Frequency (Hz)
|
* @returns {Number} Frequency (Hz)
|
||||||
*/
|
*/
|
||||||
function MIDINoteFrequency(note) {
|
function MIDINoteFrequency(note, precision=0) {
|
||||||
return Cn1_freq * Math.pow(semitone, note)
|
let freq = Cn1_freq * Math.pow(semitone, note)
|
||||||
|
return freq.toFixed(precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -90,15 +90,19 @@ class VailClient {
|
||||||
this.inputInit("#masterGain", e => {
|
this.inputInit("#masterGain", e => {
|
||||||
this.outputs.SetGain(e.target.value / 100)
|
this.outputs.SetGain(e.target.value / 100)
|
||||||
})
|
})
|
||||||
|
let toneTransform = {
|
||||||
|
note: Music.MIDINoteName,
|
||||||
|
freq: Music.MIDINoteFrequency,
|
||||||
|
}
|
||||||
this.inputInit(
|
this.inputInit(
|
||||||
"#rx-tone",
|
"#rx-tone",
|
||||||
e => this.outputs.SetMIDINote(false, e.target.value),
|
e => this.outputs.SetMIDINote(false, e.target.value),
|
||||||
Music.MIDINoteName,
|
toneTransform,
|
||||||
)
|
)
|
||||||
this.inputInit(
|
this.inputInit(
|
||||||
"#tx-tone",
|
"#tx-tone",
|
||||||
e => this.outputs.SetMIDINote(true, e.target.value),
|
e => this.outputs.SetMIDINote(true, e.target.value),
|
||||||
Music.MIDINoteName,
|
toneTransform,
|
||||||
)
|
)
|
||||||
this.inputInit("#telegraph-buzzer", e => {
|
this.inputInit("#telegraph-buzzer", e => {
|
||||||
this.setTelegraphBuzzer(e.target.checked)
|
this.setTelegraphBuzzer(e.target.checked)
|
||||||
|
@ -328,9 +332,9 @@ class VailClient {
|
||||||
*
|
*
|
||||||
* @param {string} selector CSS path to the element
|
* @param {string} selector CSS path to the element
|
||||||
* @param {function} callback Callback to call with any new value that is set
|
* @param {function} callback Callback to call with any new value that is set
|
||||||
* @param {function} transform A function to transform the value into displayed text
|
* @param {Object.<string, function>} transform Transform functions
|
||||||
*/
|
*/
|
||||||
inputInit(selector, callback, transform=null) {
|
inputInit(selector, callback, transform={}) {
|
||||||
let element = document.querySelector(selector)
|
let element = document.querySelector(selector)
|
||||||
if (!element) {
|
if (!element) {
|
||||||
console.warn("Unable to find an input to init", selector)
|
console.warn("Unable to find an input to init", selector)
|
||||||
|
@ -342,7 +346,7 @@ class VailClient {
|
||||||
element.checked = (storedValue == "on")
|
element.checked = (storedValue == "on")
|
||||||
}
|
}
|
||||||
let id = element.id
|
let id = element.id
|
||||||
let outputElement = document.querySelector(`[for="${id}"]`)
|
let outputElements = document.querySelectorAll(`[for="${id}"]`)
|
||||||
|
|
||||||
element.addEventListener("input", e => {
|
element.addEventListener("input", e => {
|
||||||
let value = element.value
|
let value = element.value
|
||||||
|
@ -351,12 +355,13 @@ class VailClient {
|
||||||
}
|
}
|
||||||
localStorage[element.id] = value
|
localStorage[element.id] = value
|
||||||
|
|
||||||
let displayValue = value
|
for (let e of outputElements) {
|
||||||
if (transform) {
|
if (e.dataset.transform) {
|
||||||
displayValue = transform(value)
|
let tf = transform[e.dataset.transform]
|
||||||
}
|
e.value = tf(value)
|
||||||
if (outputElement) {
|
} else {
|
||||||
outputElement.value = displayValue
|
e.value = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(e)
|
callback(e)
|
||||||
|
|
|
@ -66,7 +66,7 @@ export const Xlat = {
|
||||||
"wpm": "WPM",
|
"wpm": "WPM",
|
||||||
"ms": "ms",
|
"ms": "ms",
|
||||||
"wiki": "Help",
|
"wiki": "Help",
|
||||||
"rx-delay": "receive delay",
|
"rx-delay": "rx delay",
|
||||||
"telegraph-sounds": "Telegraph sounds"
|
"telegraph-sounds": "Telegraph sounds"
|
||||||
},
|
},
|
||||||
"title": {
|
"title": {
|
||||||
|
|
Loading…
Reference in New Issue