index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div id="app">
  3. <div id="app-wrapper">
  4. <div id="gadgety-view">
  5. <div id="left-bar">
  6. <div class="sequencer-wrapper" v-for="line in lines" :key='line.id'>
  7. <sequencer class="jsonSequencer" :id='line.id' :line='line'></sequencer>
  8. </div>
  9. <div class="icon-button" v-on:click="addLine()"></div>
  10. </div>
  11. <div class="icon-wrapper">
  12. <input type="number" style="width:5em;height:2em;background:red;border:none;color:white;" v-model="bpm" >
  13. <input type="submit" value="Send!" style="width:5em;height:2em;background:red;border:none;color:white;" v-on:click="getSequencerData()">
  14. </div>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import sequencer from '~/components/sequencer.vue'
  21. import sequencerDivided from '~/components/sequencerDivided.vue'
  22. import beatMenu from '~/components/beatMenu.vue'
  23. import moduleData from '~/assets/js/moduleData.json'
  24. export default {
  25. data() {
  26. return {
  27. lines: [],
  28. // https://stackoverflow.com/questions/44869287/set-object-in-data-from-a-method-in-vue-js#44869373
  29. // creata object in data vue
  30. bpm:120
  31. }
  32. },
  33. components: {
  34. sequencer,
  35. sequencerDivided,
  36. beatMenu
  37. },
  38. methods:
  39. {
  40. addLine: function (){
  41. this.lines.push({
  42. id: this.lines.length,
  43. slotSlider: 16,
  44. pulseSlider: 3,
  45. euclideanList: [],
  46. barOpacity:1,
  47. sequenceMilliseconds:3600,
  48. sampleType:1,
  49. sampleLengths: [285, 110, 175, 560]
  50. });
  51. },
  52. getSequencerData: function(){
  53. var modelEsp = {
  54. 'millis_per_slot': Math.floor(60000 / this.bpm), // bpm = 60000 / millis_per_slot
  55. 'lines': this.lines.map(function(line) {
  56. return line.euclideanList.reduce(function(acc, x) { return acc + x.toString(); }, '');
  57. })
  58. };
  59. var xhr = new XMLHttpRequest();
  60. xhr.open('POST', '/play.ws');
  61. xhr.onreadystatechange = function () {
  62. if(xhr.readyState === 4 && xhr.status === 200) {
  63. //self.commits = JSON.parse(xhr.responseText);
  64. console.log("Sent", xhr.responseText);
  65. }
  66. };
  67. xhr.setRequestHeader('Content-Type', 'application/json');
  68. console.log("Sending", modelEsp);
  69. xhr.send(JSON.stringify(modelEsp));
  70. }
  71. }
  72. }
  73. </script>
  74. <style>
  75. #app{
  76. height:100vh;
  77. background-color: cornflowerblue;
  78. }
  79. #app-wrapper{
  80. height: 100%;
  81. background: brown;
  82. display: flex;
  83. }
  84. #left-bar{
  85. flex:1 1 3em;
  86. background-color: crimson;
  87. display: flex;
  88. flex-wrap: wrap;
  89. }
  90. .icon-button{
  91. width: 3em;
  92. height: 3em;
  93. background: white;
  94. background-image: url("~/assets/img/add.png");
  95. background-repeat: no-repeat;
  96. background-position: center;
  97. }
  98. .sequencer-wrapper{
  99. flex:1 1 100%;
  100. }
  101. #gadgety-view{
  102. flex: 1 1 auto;
  103. top:0;
  104. }
  105. </style>