Allow filter settings to be changed while noise is playing

This commit is contained in:
Kevin Thomas
2021-07-26 23:30:39 -07:00
parent 5557536b92
commit 310dc36501
2 changed files with 13 additions and 9 deletions

View File

@@ -100,7 +100,7 @@
v-model="isFilterEnabled" v-model="isFilterEnabled"
label="Enabled" label="Enabled"
class="mb-5" class="mb-5"
@change="updateFilter" @change="updateFilterEnabled"
/> />
</v-row> </v-row>
</v-col> </v-col>
@@ -112,6 +112,7 @@
:items="filterTypeOptions" :items="filterTypeOptions"
label="Filter Type" label="Filter Type"
class="mx-3" class="mx-3"
@change="updateFilterType"
/> />
<v-slider <v-slider
@@ -122,6 +123,7 @@
max="20000" max="20000"
min="0" min="0"
class="mx-3" class="mx-3"
@change="updateFrequencyCutoff"
> >
<template v-slot:append> <template v-slot:append>
<v-text-field <v-text-field

View File

@@ -1,4 +1,4 @@
import { Filter, Noise, Transport } from 'tone' import { Filter, Noise, Transport, getDestination } from 'tone'
export default { export default {
name: 'Noise', name: 'Noise',
@@ -26,7 +26,6 @@ export default {
}, },
methods: { methods: {
playNoise () { playNoise () {
console.log('frequencyCutoff: ', this.frequencyCutoff)
this.startDisabled = true this.startDisabled = true
Transport.cancel() Transport.cancel()
@@ -56,9 +55,6 @@ export default {
clearInterval(this.timeRemainingInterval) clearInterval(this.timeRemainingInterval)
this.timeRemaining = 0 this.timeRemaining = 0
this.noise = new Noise()
this.filter = new Filter()
}, },
startTimer () { startTimer () {
this.timeRemaining -= 1 this.timeRemaining -= 1
@@ -69,15 +65,21 @@ export default {
updateNoiseColor () { updateNoiseColor () {
this.noise.type = this.noiseColor this.noise.type = this.noiseColor
}, },
updateFilter () { updateFilterEnabled () {
console.log('change')
if (this.isFilterEnabled) { if (this.isFilterEnabled) {
this.filter = new Filter(this.frequencyCutoff, this.filterType).toDestination() this.filter = new Filter(this.frequencyCutoff, this.filterType).toDestination()
this.noise.disconnect(getDestination())
this.noise.connect(this.filter) this.noise.connect(this.filter)
} else { } else {
this.noise.disconnect(this.filter) this.noise.disconnect()
this.noise.toDestination() this.noise.toDestination()
} }
},
updateFilterType () {
this.filter.type = this.filterType
},
updateFrequencyCutoff () {
this.filter.set({ frequency: this.frequencyCutoff })
} }
} }
} }