Skip to content

Commit

Permalink
fix(waveform-editor): redraw waveform on incoming CC change (#167)
Browse files Browse the repository at this point in the history
* fix(style): style the midi dropdowns (#164)

* fix(waveform-editor): redraw waveform on incoming CC change (#166)
  • Loading branch information
2xAA authored Apr 16, 2023
1 parent da6c42a commit 2e41c1c
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/components/MDMWaveform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,38 @@ export default {
context: null,
segments: 14,
values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
ccValues: {}
ccValues: {},
storeUnsubscribe: null
};
},
created() {
for (let i = 0; i < this.segments; i += 1) {
this.ccValues[100 + i] = this.$store.state.channel1[100 + i];
this.values[i] = this.ccValues[100 + i] / 127;
}
this.updateFromStore();
this.storeUnsubscribe = this.$store.subscribe(mutation => {
let redraw = false;
if (mutation.type === "SET_CC_VALUE") {
const { cc, value } = mutation.payload;
if (
cc > 99 &&
cc < 100 + this.segments &&
this.ccValues[cc] !== value
) {
this.ccValues[cc] = value;
this.values[100 - cc] = value / 127;
redraw = true;
}
} else if (mutation.type === "SET_STATE") {
redraw = true;
this.updateFromStore();
}
if (redraw) {
this.draw();
}
});
},
mounted() {
Expand All @@ -46,6 +69,8 @@ export default {
canvas.removeEventListener("pointerdown", this.down);
document.removeEventListener("pointerup", this.up);
document.removeEventListener("pointermove", this.move);
this.storeUnsubscribe();
},
computed: {
Expand All @@ -55,6 +80,13 @@ export default {
},
methods: {
updateFromStore() {
for (let i = 0; i < this.segments; i += 1) {
this.ccValues[100 + i] = this.$store.state.channel1[100 + i];
this.values[i] = this.ccValues[100 + i] / 127;
}
},
down() {
document.addEventListener("pointerup", this.up);
document.addEventListener("pointermove", this.move);
Expand Down

0 comments on commit 2e41c1c

Please sign in to comment.