Skip to content

Commit

Permalink
Merge 2.0-midi-throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
2xAA committed Jun 3, 2018
2 parents d9d86fd + 15464c8 commit c1783a6
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 149 deletions.
33 changes: 33 additions & 0 deletions src/components/ActiveModule/OpacityControl.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<span>
<label for="">Opacity</label>
<input type="range" min="0" max="1" step="0.0001" class="opacity" v-model="alpha">
</span>
</template>

<script>
export default {
name: 'opacityControl',
props: [
'moduleName',
],
computed: {
alpha: {
get() {
return this.$store.state.modVModules.active[this.moduleName].info.alpha;
},
set(value) {
this.$store.dispatch('modVModules/setActiveModuleInfo', {
moduleName: this.moduleName,
key: 'alpha',
value,
});
},
},
},
};
</script>

<style>
</style>
27 changes: 5 additions & 22 deletions src/components/ActiveModule/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
></b-checkbox>
</div>
<div class="control-group opacity-group" v-context-menu="opacityMenuOptions">
<label for="">Opacity</label>
<input type="range" min="0" max="1" value = "1" step="any" class="opacity" v-model="opacity">
<opacity-control :module-name="moduleName"></opacity-control>
</div>
<div class="control-group blending-group">
<label for="">Blending</label>
Expand Down Expand Up @@ -72,9 +71,13 @@

<script>
import { mapGetters, mapMutations } from 'vuex';
import OpacityControl from './OpacityControl';
export default {
name: 'activeItem',
components: {
OpacityControl,
},
data() {
return {
compositeOperation: 'normal',
Expand Down Expand Up @@ -212,22 +215,12 @@
...mapMutations('modVModules', [
'setCurrentDragged',
'setModuleFocus',
'setActiveModuleAlpha',
'setActiveModuleEnabled',
'setActiveModuleCompositeOperation',
]),
...mapGetters('modVModules', [
'getActiveModule',
]),
inputOpacity(e) {
console.log(e);
},
checkEnabled(e) {
console.log(e);
},
changeBlendmode(e) {
console.log(e);
},
focusActiveModule() {
this.setModuleFocus({ activeModuleName: this.moduleName });
},
Expand Down Expand Up @@ -258,16 +251,6 @@
enabled() {
this.setActiveModuleEnabled({ moduleName: this.moduleName, enabled: this.enabled });
},
opacity() {
this.setActiveModuleAlpha({ moduleName: this.moduleName, alpha: parseFloat(this.opacity) });
},
activeModules: {
handler(value) {
this.enabled = value[this.moduleName].info.enabled;
this.opacity = value[this.moduleName].info.alpha;
},
deep: true,
},
},
filters: {
capitalize(valueIn) {
Expand Down
204 changes: 105 additions & 99 deletions src/extra/midi-assignment/assigner.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,122 @@
import EventEmitter2 from 'eventemitter2';
// import EventEmitter2 from 'eventemitter2';
import Vue from '@/main';

class MIDIAssigner extends EventEmitter2 {
constructor(settings) {
super();
function generateMidiAssigner(settings) {
const MIDIAssigner = {
access: null,
inputs: null,
assignments: new Map(),
learning: false,
toLearn: '',
snack: null,

this.access = null;
this.inputs = null;
this.assignments = new Map();
this.learning = false;
this.toLearn = '';
this.snack = null;

this.get = (key) => {
get(key) {
this.assignments.get(key);
};

if (settings.get) this.get = settings.get;
},

this.set = (key, value) => {
set(key, value) {
this.assignments.set(key, value);
};

if (settings.set) this.set = settings.set;

this.handleInputBound = this.handleInput.bind(this);
}

start() {
// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false,
}).then((access) => {
this.access = access;
this.inputs = access.inputs;

this.handleDevices(access.inputs);

access.addEventListener('statechange', (e) => {
this.handleDevices(e.currentTarget.inputs);
},

start() {
// request MIDI access
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false,
}).then((access) => {
this.access = access;
this.inputs = access.inputs;

this.handleDevices(access.inputs);

access.addEventListener('statechange', (e) => {
this.handleDevices(e.currentTarget.inputs);
});
}).catch(() => {
Vue.$dialog.alert({
title: 'MIDI Access Refused',
message: 'MIDI access was refused. Please check your MIDI permissions for modV and refresh the page',
type: 'is-danger',
hasIcon: true,
icon: 'times-circle',
iconPack: 'fa',
});
});
}).catch(() => {
} else {
Vue.$dialog.alert({
title: 'MIDI Access Refused',
message: 'MIDI access was refused. Please check your MIDI permissions for modV and refresh the page',
title: 'Outdated Browser',
message: 'Unfortunately your browser does not support WebMIDI, please update to the latest Google Chrome release',
type: 'is-danger',
hasIcon: true,
icon: 'times-circle',
iconPack: 'fa',
});
});
} else {
Vue.$dialog.alert({
title: 'Outdated Browser',
message: 'Unfortunately your browser does not support WebMIDI, please update to the latest Google Chrome release',
type: 'is-danger',
hasIcon: true,
icon: 'times-circle',
iconPack: 'fa',
});
}
}

handleDevices(inputs) {
// loop over all available inputs and listen for any MIDI input
for(let input of inputs.values()) { // eslint-disable-line
// each time there is a midi message call the onMIDIMessage function
input.removeEventListener('midimessage', this.handleInputBound);
input.addEventListener('midimessage', this.handleInputBound);
}
}

handleInput(message) {
const data = message.data;
const midiChannel = parseInt(data[1], 10);

if (this.learning) {
this.set(midiChannel, { variable: this.toLearn, value: null });
Vue.$toast.open({
message: `Learned MIDI control for ${this.toLearn.replace(',', '.')}`,
type: 'is-success',
});
this.learning = false;
this.toLearn = '';
if (this.snack) this.snack.close();
this.snack = null;
}

const assignment = this.get(midiChannel);
if (assignment) this.emit('midiAssignmentInput', midiChannel, assignment, message);
}

learn(variableName) {
this.learning = true;
this.toLearn = variableName;

this.snack = Vue.$snackbar.open({
duration: 1000 * 60 * 60,
message: `Waiting for MIDI input to learn ${variableName.replace(',', '.')}`,
type: 'is-primary',
position: 'is-bottom-right',
actionText: 'Cancel',
onAction: () => {
this.learning = false;
}
},

handleDevices(inputs) {
// loop over all available inputs and listen for any MIDI input
for(let input of inputs.values()) { // eslint-disable-line
// each time there is a midi message call the onMIDIMessage function
input.removeEventListener('midimessage', this.handleInput.bind(this));
input.addEventListener('midimessage', this.handleInput.bind(this));
}
},

handleInput(message) {
const data = message.data;
const midiChannel = parseInt(data[1], 10);

if (this.learning) {
this.set(midiChannel, { variable: this.toLearn, value: null });
Vue.$toast.open({
message: `MIDI learning cancelled for ${variableName.replace(',', '.')}`,
type: 'is-info',
message: `Learned MIDI control for ${this.toLearn.replace(',', '.')}`,
type: 'is-success',
});
this.learning = false;
this.toLearn = '';
if (this.snack) this.snack.close();
this.snack = null;
}

const assignment = this.get(midiChannel);
if (assignment && this.messageCallback) {
this.messageCallback({
midiChannel,
assignment,
message,
});
},
});
}
}
},

learn(variableName) {
this.learning = true;
this.toLearn = variableName;

this.snack = Vue.$snackbar.open({
duration: 1000 * 60 * 60,
message: `Waiting for MIDI input to learn ${variableName.replace(',', '.')}`,
type: 'is-primary',
position: 'is-bottom-right',
actionText: 'Cancel',
onAction: () => {
this.learning = false;
Vue.$toast.open({
message: `MIDI learning cancelled for ${variableName.replace(',', '.')}`,
type: 'is-info',
});
},
});
},
};

if (settings.get) MIDIAssigner.get = settings.get;
if (settings.set) MIDIAssigner.set = settings.set;
if (settings.callback) MIDIAssigner.messageCallback = settings.callback;

console.log(settings);

return MIDIAssigner;
}

export default MIDIAssigner;
export default generateMidiAssigner;

0 comments on commit c1783a6

Please sign in to comment.