Skip to content

Commit

Permalink
Fix localUpdateInProgress behavior to be time based cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkao committed Dec 12, 2020
1 parent 98d454d commit 264f25c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/Fader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default {
isMidiLocked: false,
selectedSource: '',
obsUpdateInProgress: false,
localUpdateInProgress: false
localUpdateInProgress: false,
localUpdateTimeout: null
}
},
created: function () {
Expand Down Expand Up @@ -100,7 +101,11 @@ export default {
return
}
const dB = this.sevenbitToDB(value)
if (this.localUpdateTimeout !== null) {
clearTimeout(this.localUpdateTimeout)
}
this.localUpdateInProgress = true
this.localUpdateTimeout = setTimeout(() => { this.localUpdateInProgress = false }, 300)
this.obs.send('SetVolume', { source: this.selectedSource, volume: this.dbToMul(dB), useDecibel: false })
},
faderUIChanged () {
Expand All @@ -113,26 +118,26 @@ export default {
if (this.isMidiLocked) {
this.value = this.midiValue
} else if (Math.abs(this.midiValue - this.value) < 2) {
console.log('MIDI locked on')
this.isMidiLocked = true
this.value = this.midiValue
}
},
obsVolumeChanged (data) {
if (data.sourceName === this.selectedSource) {
if (this.localUpdateInProgress) {
this.localUpdateInProgress = false
return
}
const mul = data.volume
const db = this.mulToDB(mul)
const value = this.dbToSevenbit(db)
// console.log(`OBS volume for ${this.selectedSource} changed to ${mul}, ${db}, ${value}`)
if (value !== this.value) {
this.obsUpdateInProgress = true
this.value = value
this.isMidiLocked = false
console.log(`OBS volume for ${this.selectedSource} changed to ${mul}, ${db}, ${value}`)
}
}
},
Expand Down

0 comments on commit 264f25c

Please sign in to comment.