From 15e43c28df6119821035bd6b3e7542c998163b3f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 28 May 2022 20:30:50 -0600 Subject: [PATCH] Send keyer state every time it's connected --- static/inputs.mjs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/static/inputs.mjs b/static/inputs.mjs index 290e62c..8106183 100644 --- a/static/inputs.mjs +++ b/static/inputs.mjs @@ -108,6 +108,8 @@ export class Keyboard extends Input{ export class MIDI extends Input{ constructor(keyer) { super(keyer) + this.ditDuration = 100 + this.keyerMode = 0 this.midiAccess = {outputs: []} // stub while we wait for async stuff if (navigator.requestMIDIAccess) { @@ -122,18 +124,28 @@ export class MIDI extends Input{ this.midiStateChange() } - SetDitDuration(delay) { - // Send the Vail adapter the current iambic delay setting + sendState() { for (let output of this.midiAccess.outputs.values()) { - // MIDI only supports 7-bit values, so we have to divide it by two - output.send([0xB0, 0x01, delay/2]) + // Turn off keyboard mode + output.send([0xB0, 0x00, 0x00]) + + // MIDI only supports 7-bit values, so we have to divide ditduration by two + output.send([0xB0, 0x01, this.ditDuration/2]) + + // Send keyer mode + output.send([0xC0, this.keyerMode]) } + + } + + SetDitDuration(duration) { + this.ditDuration = duration + this.sendState() } SetKeyerMode(mode) { - for (let output of this.midiAccess.outputs.values()) { - output.send([0xC0, mode]) - } + this.keyerMode = mode + this.sendState() } midiStateChange(event) { @@ -146,9 +158,7 @@ export class MIDI extends Input{ } // Tell the Vail adapter to disable keyboard events: we can do MIDI! - for (let output of this.midiAccess.outputs.values()) { - output.send([0xB0, 0x00, 0x00]) // Turn off keyboard mode - } + this.sendState() } midiMessage(event) {