Send keyer state every time it's connected

This commit is contained in:
Neale Pickett 2022-05-28 20:30:50 -06:00
parent b7de5cf8cb
commit 15e43c28df
1 changed files with 20 additions and 10 deletions

View File

@ -108,6 +108,8 @@ export class Keyboard extends Input{
export class MIDI extends Input{ export class MIDI extends Input{
constructor(keyer) { constructor(keyer) {
super(keyer) super(keyer)
this.ditDuration = 100
this.keyerMode = 0
this.midiAccess = {outputs: []} // stub while we wait for async stuff this.midiAccess = {outputs: []} // stub while we wait for async stuff
if (navigator.requestMIDIAccess) { if (navigator.requestMIDIAccess) {
@ -122,18 +124,28 @@ export class MIDI extends Input{
this.midiStateChange() this.midiStateChange()
} }
SetDitDuration(delay) { sendState() {
// Send the Vail adapter the current iambic delay setting
for (let output of this.midiAccess.outputs.values()) { for (let output of this.midiAccess.outputs.values()) {
// MIDI only supports 7-bit values, so we have to divide it by two // Turn off keyboard mode
output.send([0xB0, 0x01, delay/2]) 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) { SetKeyerMode(mode) {
for (let output of this.midiAccess.outputs.values()) { this.keyerMode = mode
output.send([0xC0, mode]) this.sendState()
}
} }
midiStateChange(event) { midiStateChange(event) {
@ -146,9 +158,7 @@ export class MIDI extends Input{
} }
// Tell the Vail adapter to disable keyboard events: we can do MIDI! // Tell the Vail adapter to disable keyboard events: we can do MIDI!
for (let output of this.midiAccess.outputs.values()) { this.sendState()
output.send([0xB0, 0x00, 0x00]) // Turn off keyboard mode
}
} }
midiMessage(event) { midiMessage(event) {