From f8b5cf22afc69062f67e6855b0f848e01664113e Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Sat, 25 Feb 2023 18:12:17 -0700 Subject: [PATCH] Adapter: actually change pitches --- static/index.html | 46 +++++++++++++++++++------------------- static/scripts/inputs.mjs | 7 ++++-- static/scripts/noise.mjs | 9 +++++--- static/scripts/outputs.mjs | 6 ++--- static/scripts/vail.mjs | 5 ++++- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/static/index.html b/static/index.html index 946514a..d925441 100644 --- a/static/index.html +++ b/static/index.html @@ -269,29 +269,6 @@ -
-
- -
-
-
-
- -
-
-
-
-

+
+
+ +
+
+
+
+ +
+
+
+
+
diff --git a/static/scripts/inputs.mjs b/static/scripts/inputs.mjs index e3e2e21..ec289d2 100644 --- a/static/scripts/inputs.mjs +++ b/static/scripts/inputs.mjs @@ -123,19 +123,22 @@ export class MIDI extends Input{ super(keyer) this.ditDuration = 100 this.keyerMode = 0 - + this.midiAccess = {outputs: []} // stub while we wait for async stuff if (navigator.requestMIDIAccess) { this.midiInit() } } - + async midiInit(access) { this.inputs = [] this.midiAccess = await navigator.requestMIDIAccess() this.midiAccess.addEventListener("statechange", e => this.midiStateChange(e)) this.midiStateChange() } + + // If you're looking for the thing that sets the tx tone, + // that's in outputs.mjs:SetMIDINote sendState() { for (let output of this.midiAccess.outputs.values()) { diff --git a/static/scripts/noise.mjs b/static/scripts/noise.mjs index 2f72cd7..cb97bd2 100644 --- a/static/scripts/noise.mjs +++ b/static/scripts/noise.mjs @@ -44,23 +44,26 @@ class Noise extends AudioSource { modulatorGain: new GainNode(context), filter: WhiteNoise(context), filterGain: new GainNode(context), + filterGainModulator: new OscillatorNode(context), + filterGainModulatorGain: new GainNode(context), } wn.modulator.frequency.value = 0 wn.modulatorGain.gain.value = 0 wn.filter.frequency.value = 800 wn.filterGain.gain.value = 0.8 / noises + wn.filterGainModulator.frequency.value = 1 + wn.filterGainModulatorGain.gain.value = 1 wn.modulator.connect(wn.modulatorGain) wn.modulatorGain.connect(wn.filter.frequency) - wn.filter.connect(wn.filterGain) - wn.filterGain.connect(this.masterGain) + wn.filter.connect(this.masterGain) wn.modulator.start() this.whiteNoise.push(wn) } - this.SetNoiseParams(0, 0.07, 70, 400, 0.4) + this.SetNoiseParams(0, 0.07, 70, 400, 0.0) this.SetNoiseParams(1, 0.03, 200, 1600, 0.4) this.masterGain.gain.value = 0.5 } diff --git a/static/scripts/outputs.mjs b/static/scripts/outputs.mjs index 4d91455..73d40b5 100644 --- a/static/scripts/outputs.mjs +++ b/static/scripts/outputs.mjs @@ -423,7 +423,6 @@ class MIDIBuzzer extends Buzzer { if (tx) { return } - this.sendAt(when, [0x90, this.note, 0x7f]) } @@ -443,9 +442,10 @@ class MIDIBuzzer extends Buzzer { */ SetMIDINote(tx, note) { if (tx) { - return + this.sendAt(0, [0xB0, 0x02, note]) + } else { + this.note = note } - this.note = note } } diff --git a/static/scripts/vail.mjs b/static/scripts/vail.mjs index 38d3923..4596f09 100644 --- a/static/scripts/vail.mjs +++ b/static/scripts/vail.mjs @@ -106,7 +106,10 @@ class VailClient { } this.inputInit( "#rx-tone", - e => this.outputs.SetMIDINote(false, e.target.value), + e => { + this.noise.SetNoiseFrequency(1, Music.MIDINoteFrequency(e.target.value)) + this.outputs.SetMIDINote(false, e.target.value) + }, toneTransform, ) this.inputInit(