Gadgety_Euclidean_Sequencer.../pages/index.vue

116 lines
2.8 KiB
Vue
Raw Normal View History

2018-09-05 19:17:08 +02:00
<template>
<div id="app">
2018-09-16 22:25:38 +02:00
<div id="app-wrapper">
<div id="gadgety-view">
<div id="left-bar">
<div class="sequencer-wrapper" v-for="line in lines" :key='line.id'>
<sequencer class="jsonSequencer" :id='line.id' :line='line'></sequencer>
</div>
<div class="icon-button" v-on:click="addLine()"></div>
2018-09-09 23:59:01 +02:00
</div>
2018-09-16 22:25:38 +02:00
<div class="icon-wrapper">
<input type="number" style="width:5em;height:2em;background:red;border:none;color:white;" v-model="bpm" >
<input type="submit" value="Send!" style="width:5em;height:2em;background:red;border:none;color:white;" v-on:click="getSequencerData()">
</div>
2018-09-09 23:59:01 +02:00
</div>
</div>
2018-09-05 19:17:08 +02:00
</div>
</template>
<script>
import sequencer from '~/components/sequencer.vue'
import sequencerDivided from '~/components/sequencerDivided.vue'
import beatMenu from '~/components/beatMenu.vue'
2018-09-09 23:59:01 +02:00
import moduleData from '~/assets/js/moduleData.json'
2018-09-05 19:17:08 +02:00
export default {
2018-09-09 23:59:01 +02:00
data() {
return {
2018-09-16 22:25:38 +02:00
lines: [],
2018-09-09 23:59:01 +02:00
// https://stackoverflow.com/questions/44869287/set-object-in-data-from-a-method-in-vue-js#44869373
// creata object in data vue
2018-09-16 22:25:38 +02:00
bpm:120
2018-09-09 23:59:01 +02:00
}
},
2018-09-05 19:17:08 +02:00
components: {
sequencer,
sequencerDivided,
beatMenu
2018-09-09 23:59:01 +02:00
},
methods:
{
addLine: function (){
this.lines.push({
id: this.lines.length,
slotSlider: 16,
pulseSlider: 3,
euclideanList: [],
2018-09-18 13:20:16 +02:00
barOpacity:1,
2018-09-18 20:11:38 +02:00
sequenceMilliseconds:3600,
sampleType:1,
sampleLengths: [285, 110, 175, 560]
});
2018-09-09 23:59:01 +02:00
},
getSequencerData: function(){
var modelEsp = {
2018-09-16 22:25:38 +02:00
'millis_per_slot': Math.floor(60000 / this.bpm), // bpm = 60000 / millis_per_slot
2018-09-09 23:59:01 +02:00
'lines': this.lines.map(function(line) {
return line.euclideanList.reduce(function(acc, x) { return acc + x.toString(); }, '');
})
};
var xhr = new XMLHttpRequest();
xhr.open('POST', '/play.ws');
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
//self.commits = JSON.parse(xhr.responseText);
2018-09-16 22:25:38 +02:00
console.log("Sent", xhr.responseText);
2018-09-09 23:59:01 +02:00
}
};
xhr.setRequestHeader('Content-Type', 'application/json');
2018-09-16 22:25:38 +02:00
console.log("Sending", modelEsp);
2018-09-09 23:59:01 +02:00
xhr.send(JSON.stringify(modelEsp));
}
2018-09-05 19:17:08 +02:00
}
}
</script>
2018-09-16 22:25:38 +02:00
2018-09-05 19:17:08 +02:00
<style>
2018-09-16 22:25:38 +02:00
#app{
height:100vh;
background-color: cornflowerblue;
}
#app-wrapper{
height: 100%;
background: brown;
display: flex;
}
#left-bar{
flex:1 1 3em;
background-color: crimson;
display: flex;
flex-wrap: wrap;
}
2018-09-05 19:17:08 +02:00
.icon-button{
2018-09-16 22:25:38 +02:00
width: 3em;
height: 3em;
background: white;
background-image: url("~/assets/img/add.png");
background-repeat: no-repeat;
background-position: center;
2018-09-05 19:17:08 +02:00
}
2018-09-16 22:25:38 +02:00
.sequencer-wrapper{
flex:1 1 100%;
}
#gadgety-view{
flex: 1 1 auto;
top:0;
2018-09-05 19:17:08 +02:00
}
</style>