Skip to content

Commit

Permalink
fix: fix stuttering when adjusting volume with rotary encoders
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaggernaut555 committed Mar 18, 2022
1 parent 50d0c37 commit 4387601
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ interface Settings {
}

class eAssignment extends Assignment {
meterInterval: NodeJS.Timeout = {} as NodeJS.Timeout
meterInterval: NodeJS.Timeout = {} as NodeJS.Timeout;
updated: boolean = false;
}

// buttons will need to define how they are updated
Expand Down Expand Up @@ -108,12 +109,14 @@ function init_buttons() {
function init_strips(strips: OutParam[]) {
for (let i = 0; i < stripCount; i++) {
strip[i] = new eAssignment(`Strip ${i}`, {
name: `Strip ${i}: ${strips[i].name}`
name: `Strip ${i}: ${strips[i].name}`,
throttle: 100,
});

strip[i].assigned = true;

strip[i].on("volumeChanged", (level: number) => {
strip[i].updated = true;
strip[i].volume = level;
vm.setStripParameter("gain", i, convertVolumeToGain(level));
});
Expand Down Expand Up @@ -146,10 +149,12 @@ function init_strips(strips: OutParam[]) {
function init_buses(buses: OutParam[]) {
for (let i = 0; i < busCount; i++) {
bus[i] = new eAssignment(`Bus ${i}`, {
name: `Bus ${i}: ${buses[i].name}`
name: `Bus ${i}: ${buses[i].name}`,
throttle: 100,
});

bus[i].on("volumeChanged", (level: number) => {
bus[i].updated = true;
bus[i].volume = level;
vm.setBusParameter("gain", i, convertVolumeToGain(level));
});
Expand Down Expand Up @@ -199,12 +204,15 @@ function update_all() {
let anySelected = false;
data.buses.forEach((i) => {
bus[i.id].muted = i.mute;
bus[i.id].volume = convertGainToVolume(i.gain);
if (!bus[i.id].updated) {
bus[i.id].volume = convertGainToVolume(i.gain);
}
bus[i.id].assigned = i.Sel;
if (i.Sel) {
selectedBus = i.id;
anySelected = true;
}
bus[i.id].updated = false
});

if (!anySelected) {
Expand All @@ -214,12 +222,18 @@ function update_all() {
data.strips.forEach((i) => {
strip[i.id].muted = i.mute;
strip[i.id].running = i.solo;
if (selectedBus !== null) {
strip[i.id].volume = convertGainToVolume(i[`GainLayer[${selectedBus}]` as StripParamName]);
}
else {
strip[i.id].volume = convertGainToVolume(i.gain);
if (!strip[i.id].updated) {
if (selectedBus !== null) {
strip[i.id].volume = convertGainToVolume(i[`GainLayer[${selectedBus}]` as StripParamName]);
}
else {
let vol = convertGainToVolume(i.gain);
if (vol != strip[i.id].volume) {
strip[i.id].volume = vol;
}
}
}
strip[i.id].updated = false
});
});
}
Expand Down

0 comments on commit 4387601

Please sign in to comment.