From 3072c82468a41241847fc9d2e74678be655be6e5 Mon Sep 17 00:00:00 2001 From: "Rick.Games" Date: Mon, 11 Jul 2022 21:00:42 +0200 Subject: [PATCH 1/2] Volume sliders added for output monitor mix and stream mix --- src/WaveLinkClient.js | 12 ++++++++ src/main.ts | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/WaveLinkClient.js b/src/WaveLinkClient.js index e020fef..e620fdb 100644 --- a/src/WaveLinkClient.js +++ b/src/WaveLinkClient.js @@ -423,6 +423,18 @@ class WaveLinkClient { } } + setOutputVolume(slider, targetVol, muted) { + if (slider == "local") { + this.output.localVolOut = targetVol + this.output.isLocalMuteOut = undefined !== muted ? muted : false + } else { + this.output.streamVolOut = targetVol + this.output.isStreamMuteOut = undefined !== muted ? muted : false + } + + return this.setOutputMixer() + } + setVolume(mixerTyp, mixerId, slider, targetVol, delay) { var timeLeft = delay var volumeSteps = 0, diff --git a/src/main.ts b/src/main.ts index 3a4af89..0b8d25a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -255,6 +255,75 @@ async function initialize() { console.log(`Found ${Object.keys(mixerMap).length} mixers`) console.log(mixerMap) + + // Volume sliders for output mix + // Get current output volumes + var outputVolume = await client.getMonitoringState(); + + // // Create slider for monitor output + var monitor_mixer_volume = outputVolume.localVolOut + var monitor_mixer_muted = outputVolume.isLocalMuteOut + const monitor_mixer = new Assignment("wavelink_monitor_mix_volume", { + name: `Monitor Mix Volume`, + muted: monitor_mixer_muted, + volume: volumeWaveLinkToMM(monitor_mixer_volume), + }) + + // Guess we need to "set it harder" (?) + setTimeout(() => { + monitor_mixer.volume = volumeWaveLinkToMM(monitor_mixer_volume) + monitor_mixer.muted = monitor_mixer_muted + }, 100) + + monitor_mixer.on("volumeChanged", (level: number) => { + client.setOutputVolume( + "local", + volumeMMToWaveLink(level) + ) + }) + + monitor_mixer.on("mutePressed", () => { + client.setMute("output", null, "local") + monitor_mixer.muted = client.output?.isLocalMuteOut + }) + + // Add slider for stream mix output volume + var stream_mixer_volume = outputVolume.streamVolOut + var stream_mixer_muted = outputVolume.isStreamMuteOut + + const stream_mixer = new Assignment("wavelink_stream_mix_volume", { + name: `Stream Mix Volume`, + muted: stream_mixer_muted, + volume: volumeWaveLinkToMM(stream_mixer_volume), + }) + + // Guess we need to "set it harder" (?) + setTimeout(() => { + stream_mixer.volume = volumeWaveLinkToMM(stream_mixer_volume) + stream_mixer.muted = stream_mixer_muted + }, 100) + + stream_mixer.on("volumeChanged", (level: number) => { + client.setOutputVolume( + "stream", + volumeMMToWaveLink(level) + ) + }) + + stream_mixer.on("mutePressed", () => { + client.setMute("output", null, "stream") + stream_mixer.muted = client.output?.isStreamMuteOut + }) + + client.event!.on("outputMixerChanged", () => { + if (client.output) + { + monitor_mixer.volume = volumeWaveLinkToMM(client.output.localVolOut) + monitor_mixer.muted = client.output.isLocalMuteOut + stream_mixer.volume = volumeWaveLinkToMM(client.output.streamVolOut) + stream_mixer.muted = client.output.isStreamMuteOut + } + }) } initialize().then(() => console.log("started!")) From 5242252150d83fb6d74bfd87a5e2cd23e5fb165b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Wed, 13 Jul 2022 21:37:22 +0200 Subject: [PATCH 2/2] Style Cleanups --- src/main.ts | 110 ++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0b8d25a..be4c269 100644 --- a/src/main.ts +++ b/src/main.ts @@ -91,7 +91,10 @@ function volumeWaveLinkToMM(vol: number) { } const mixerTypes = ["local", "stream"] -let mixerMap: Record +let mixerMap: Record< + string, + { mixer: Mixer | undefined; assignment: Assignment } +> const buttonList: Record = {} function createMixerAssignment( @@ -258,71 +261,58 @@ async function initialize() { // Volume sliders for output mix // Get current output volumes - var outputVolume = await client.getMonitoringState(); - - // // Create slider for monitor output - var monitor_mixer_volume = outputVolume.localVolOut - var monitor_mixer_muted = outputVolume.isLocalMuteOut - const monitor_mixer = new Assignment("wavelink_monitor_mix_volume", { - name: `Monitor Mix Volume`, - muted: monitor_mixer_muted, - volume: volumeWaveLinkToMM(monitor_mixer_volume), - }) - - // Guess we need to "set it harder" (?) - setTimeout(() => { - monitor_mixer.volume = volumeWaveLinkToMM(monitor_mixer_volume) - monitor_mixer.muted = monitor_mixer_muted - }, 100) - - monitor_mixer.on("volumeChanged", (level: number) => { - client.setOutputVolume( - "local", - volumeMMToWaveLink(level) + const outputVolume = await client.getMonitoringState() + + // Set up sliders for final headphone and stream output + const localAndStream = [true, false] + + localAndStream.forEach((isLocal) => { + // Create slider for monitor output + const mixerVolume = isLocal + ? outputVolume.localVolOut + : outputVolume.streamVolOut + + const mixerMuted = isLocal + ? outputVolume.isLocalMuteOut + : outputVolume.isStreamMuteOut + + const mixer = new Assignment( + `wavelink_monitor_${isLocal ? "local" : "stream"}_volume`, + { + name: isLocal ? `Monitor Mix Volume` : `Stream Mix Volume`, + muted: mixerMuted, + volume: volumeWaveLinkToMM(mixerVolume), + } ) - }) - - monitor_mixer.on("mutePressed", () => { - client.setMute("output", null, "local") - monitor_mixer.muted = client.output?.isLocalMuteOut - }) - // Add slider for stream mix output volume - var stream_mixer_volume = outputVolume.streamVolOut - var stream_mixer_muted = outputVolume.isStreamMuteOut - - const stream_mixer = new Assignment("wavelink_stream_mix_volume", { - name: `Stream Mix Volume`, - muted: stream_mixer_muted, - volume: volumeWaveLinkToMM(stream_mixer_volume), - }) + // Set volume even harder + setTimeout(() => { + mixer.volume = volumeWaveLinkToMM(mixerVolume) + mixer.muted = mixerMuted + }, 100) - // Guess we need to "set it harder" (?) - setTimeout(() => { - stream_mixer.volume = volumeWaveLinkToMM(stream_mixer_volume) - stream_mixer.muted = stream_mixer_muted - }, 100) + const volType = isLocal ? "local" : "stream" + mixer.on("volumeChanged", (level: number) => { + client.setOutputVolume(volType, volumeMMToWaveLink(level)) + }) - stream_mixer.on("volumeChanged", (level: number) => { - client.setOutputVolume( - "stream", - volumeMMToWaveLink(level) - ) - }) + mixer.on("mutePressed", () => { + client.setMute("output", null, volType) + mixer.muted = client.output!.isLocalMuteOut + }) - stream_mixer.on("mutePressed", () => { - client.setMute("output", null, "stream") - stream_mixer.muted = client.output?.isStreamMuteOut - }) + client.event!.on("outputMixerChanged", () => { + if (client.output) { + mixer.volume = volumeWaveLinkToMM( + isLocal ? client.output.localVolOut : client.output.streamVolOut + ) + mixer.muted = isLocal + ? client.output.isLocalMuteOut + : client.output.isStreamMuteOut + } + }) - client.event!.on("outputMixerChanged", () => { - if (client.output) - { - monitor_mixer.volume = volumeWaveLinkToMM(client.output.localVolOut) - monitor_mixer.muted = client.output.isLocalMuteOut - stream_mixer.volume = volumeWaveLinkToMM(client.output.streamVolOut) - stream_mixer.muted = client.output.isStreamMuteOut - } + mixerMap[mixer.id] = { mixer: undefined, assignment: mixer } }) }