Skip to content

Commit

Permalink
Merge branch 'monitor-stream-mix-volume'
Browse files Browse the repository at this point in the history
* monitor-stream-mix-volume:
  Style Cleanups
  Volume sliders added for output monitor mix and stream mix
  • Loading branch information
anaisbetts committed Jul 13, 2022
2 parents 56f48be + 5242252 commit 2373085
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/WaveLinkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
61 changes: 60 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ function volumeWaveLinkToMM(vol: number) {
}

const mixerTypes = ["local", "stream"]
let mixerMap: Record<string, { mixer: Mixer; assignment: Assignment }>
let mixerMap: Record<
string,
{ mixer: Mixer | undefined; assignment: Assignment }
>
const buttonList: Record<string, ButtonType> = {}

function createMixerAssignment(
Expand Down Expand Up @@ -255,6 +258,62 @@ async function initialize() {

console.log(`Found ${Object.keys(mixerMap).length} mixers`)
console.log(mixerMap)

// Volume sliders for output mix
// Get current output volumes
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),
}
)

// Set volume even harder
setTimeout(() => {
mixer.volume = volumeWaveLinkToMM(mixerVolume)
mixer.muted = mixerMuted
}, 100)

const volType = isLocal ? "local" : "stream"
mixer.on("volumeChanged", (level: number) => {
client.setOutputVolume(volType, volumeMMToWaveLink(level))
})

mixer.on("mutePressed", () => {
client.setMute("output", null, volType)
mixer.muted = client.output!.isLocalMuteOut
})

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
}
})

mixerMap[mixer.id] = { mixer: undefined, assignment: mixer }
})
}

initialize().then(() => console.log("started!"))
Expand Down

0 comments on commit 2373085

Please sign in to comment.