This repository has been archived on 2019-03-23. You can view files and clone it, but cannot push or open issues/pull-requests.
binauralbeats/src/components/Main.vue

98 lines
2.4 KiB
Vue
Raw Normal View History

2018-02-21 20:07:24 +01:00
<template>
<div class="main">
2018-02-21 20:33:38 +01:00
<h1>Binaural Beats {{ started ? 'started' : 'stopped' }}</h1>
2018-02-21 20:07:24 +01:00
<button v-on:click="start">Start</button>
<button v-on:click="stop">Stop</button>
<select v-model="waveform">
2018-02-21 20:33:38 +01:00
<option disabled value="">Waveform</option>
2018-02-21 20:07:24 +01:00
<option>sine</option>
<option>square</option>
<option>triangle</option>
2018-02-21 20:33:38 +01:00
<option>sawtooth</option>
2018-02-21 20:07:24 +01:00
</select>
<input v-model="leftEar.frequency.value">
2018-02-21 20:33:38 +01:00
<input v-model="rightEar.frequency.value">
<select v-model="preset">
<option disabled value="">Preset</option>
<option value="alpha">α waves</option>
<option value="beta">β waves</option>
<option value="gamma">γ waves</option>
<option value="delta">δ waves</option>
<option value="theta">θ waves</option>
</select>
2018-02-21 20:07:24 +01:00
</div>
</template>
<script>
import Tone from 'tone'
export default {
name: 'Main',
data () {
return {
2018-02-21 20:33:38 +01:00
started: false,
2018-02-21 20:07:24 +01:00
merge: null,
leftEar: null,
rightEar: null,
waveform: 'sine',
2018-02-21 20:33:38 +01:00
preset: null,
presets: {
alpha: {
waveform: 'sine',
right: 150,
left: 155
},
beta: {
waveform: 'sine',
right: 130,
left: 139
}
}
2018-02-21 20:07:24 +01:00
}
},
created () {
this.init()
},
methods: {
init: function () {
this.merge = new Tone.Merge().toMaster()
this.leftEar = new Tone.Oscillator().connect(this.merge.left)
this.rightEar = new Tone.Oscillator().connect(this.merge.right)
this.leftEar.frequency.value = 440
this.rightEar.frequency.value = 430
},
start: function () {
this.leftEar.start()
this.rightEar.start()
2018-02-21 20:33:38 +01:00
this.started = true
2018-02-21 20:07:24 +01:00
},
stop: function () {
this.leftEar.stop()
this.rightEar.stop()
2018-02-21 20:33:38 +01:00
this.started = false
2018-02-21 20:07:24 +01:00
}
},
watch: {
waveform: function () {
2018-02-21 20:33:38 +01:00
this.leftEar.type = this.waveform
this.rightEar.type = this.waveform
},
preset: function () {
this.waveform = this.presets[this.preset].waveform
this.leftEar.frequency.value = this.presets[this.preset].left
this.rightEar.frequency.value = this.presets[this.preset].right
2018-02-21 20:07:24 +01:00
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
2018-02-21 20:33:38 +01:00
button, select, input {
color: black;
background-color: white;
border-width: 1px;
border-style: solid;
}
2018-02-21 20:07:24 +01:00
</style>