Skip to content

Commit

Permalink
feat(midi): adds multi-channel midi support (#91)
Browse files Browse the repository at this point in the history
* add function to receive cc messages from a controller

* receive cc from controller

* use channel of a note to send it through

* use channel of a cc to set thannel without gui

* fix notes off when playing more than one channel

* feat(midi): adds program change for instrument selection (#89)

* clean up before pull request

Co-authored-by: umanema <[email protected]>
Co-authored-by: Sam Wray <[email protected]>
  • Loading branch information
3 people authored Sep 22, 2021
1 parent 79fb45d commit 96b3b50
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
25 changes: 23 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export default {
} = e;
const note = `${name}${octave}`;
let channel = this.channel;
let channel = e.channel;
if (this.polyphonic) {
channel = this.nextPolyphonyChannel(number);
Expand All @@ -488,8 +488,14 @@ export default {
const { name, octave, number } = e.note;
const note = `${name}${octave}`;
let channel;
if (this.polyphonic) {
channel = this.notesOn[number];
} else {
channel = e.channel;
}
this.outputPort.stopNote(note, this.notesOn[number]);
this.outputPort.stopNote(note, channel);
delete this.notesOn[number];
},
Expand All @@ -508,6 +514,19 @@ export default {
}
},
handleCC(e) {
this.$store.dispatch("setCCValuesOnChannel", {
[e.controller.number]: this.inverse
? 127 - e.value
: e.value,
channel: e.channel
});
if (!this.outputPort) {
return;
}
},
async handleProgramChange(e) {
if (!this.outputPort) {
return;
Expand Down Expand Up @@ -585,6 +604,8 @@ export default {
// Listen for a pitch bend message on all channels
input.addListener("pitchbend", "all", this.handlePitchBend);
input.addListener("controlchange", "all", this.handleCC);
// Listen for a program change message on all channels
input.addListener("programchange", "all", this.handleProgramChange);
}
Expand Down
1 change: 0 additions & 1 deletion src/components/DraggableSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export default {
);
this.internalValue = clampedNewIndex;
this.$emit(
"input",
this.emitArrayValue ? values[clampedNewIndex] : clampedNewMIDIValue
Expand Down
5 changes: 2 additions & 3 deletions src/components/MDMDial.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default {
this.storeUnsubscribe = this.$store.subscribe(mutation => {
if (mutation.type === "SET_CC_VALUE") {
const { cc, value } = mutation.payload;
const { cc, value, channel } = mutation.payload;
if (cc === this.cc + this.ccOffset && !this.mouseButtonDown) {
if (cc === this.cc + this.ccOffset && !this.mouseButtonDown && channel === this.$store.state.channel) {
this.movementValue = this.inverse ? -value + 127 : value;
this.draw();
}
Expand Down Expand Up @@ -165,7 +165,6 @@ export default {
this.movementValue = clampedNewValue;
this.downY = e.pageY;
this.$store.dispatch("setCCValues", {
values: {
[this.cc + this.ccOffset]: this.inverse
Expand Down
28 changes: 28 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ const store = new Vuex.Store({
});
},

setCCValuesOnChannel({ commit, state }, values = {}) {
Object.keys(values).forEach(key => {
if (parseInt(key, 10) === NaN) {
return;
}
const cc = parseInt(key, 10);

const value = values[cc];
const isGlobal = GLOBAL_CC.indexOf(cc) > -1;

if (state.polyphonic || isGlobal) {
for (let i = 1; i < 7; ++i) {
if (state[`channel${i}`][cc] === value) {
continue;
}

commit("SET_CC_VALUE", { cc, value, channel: i });
}
} else {
if (state[`channel${values.channel}`][cc] === value) {
return;
}

commit("SET_CC_VALUE", { cc, value, channel: values.channel });
}
});
},

setChannel({ commit }, channel) {
commit("SET_CHANNEL", channel);
},
Expand Down

0 comments on commit 96b3b50

Please sign in to comment.