From bca1faebbbeb692f3da168e340ca8438bdb64f29 Mon Sep 17 00:00:00 2001 From: KevinNThomas Date: Sun, 18 Jul 2021 21:59:00 -0700 Subject: [PATCH] Add filter section --- .eslintrc.js | 10 +++++--- src/components/Noise.vue | 55 +++++++++++++++++++++++++++++++++++++--- src/components/noise.js | 25 +++++++++++++----- 3 files changed, 78 insertions(+), 12 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 275e28b..766fc13 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,12 +1,16 @@ module.exports = { extends: [ // add more generic rulesets here, such as: - // 'eslint:recommended', + "eslint:recommended", // 'plugin:vue/vue3-recommended', - 'plugin:vue/recommended' // Use this if you are using Vue.js 2.x. + "plugin:vue/recommended" // Use this if you are using Vue.js 2.x. ], rules: { // override/add rules settings here, such as: // 'vue/no-unused-vars': 'error' + "eol-last": 1 + }, + "env": { + "node": true } -} \ No newline at end of file +} diff --git a/src/components/Noise.vue b/src/components/Noise.vue index fd3fbc0..8ff528d 100644 --- a/src/components/Noise.vue +++ b/src/components/Noise.vue @@ -24,14 +24,14 @@ Start Stop @@ -58,12 +58,14 @@ v-model="noiseVolume" label="Volume" class="mx-3" + :disabled="startDisabled" /> + + +

+ Filter +

+ + + + +
+ + + + + + + + + + diff --git a/src/components/noise.js b/src/components/noise.js index 719d4c2..1cfc6ca 100644 --- a/src/components/noise.js +++ b/src/components/noise.js @@ -1,4 +1,4 @@ -import { Noise, Transport } from "tone"; +import { Filter, Noise, Transport } from "tone"; export default { name: "Noise", @@ -9,23 +9,36 @@ export default { timeRemaining: 0, noiseColorOptions: ["pink", "white", "brown"], noiseColor: "pink", - noiseVolume: -10 + noiseVolume: -10, + isFilterEnabled: false, + frequencyCutoff: 20000, + filterTypeOptions: ["lowpass", "highpass", "bandpass", "lowshelf", "highshelf", "notch", "allpass", "peaking"], + filterType: "lowpass" }), created() { this.noise = new Noise() }, methods: { - handleStart() { + playNoise() { this.startDisabled = true Transport.cancel() - this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).toDestination() + + this.filter = new Filter(this.frequencyCutoff, this.filterType).toDestination() + + if (this.isFilterEnabled) { + this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).connect(this.filter) + } else { + this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).toDestination() + } this.noise.sync().start(0).stop(this.noiseDuration) + Transport.start() Transport.loopEnd = this.noiseDuration + this.transportInterval = setInterval(() => this.stopTransport(), this.noiseDuration * 1000 + 100) this.timeRemaining = this.noiseDuration - this.timeRemainingInterval = setInterval(() => this.timer(), 1000) + this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000) }, stopTransport() { clearInterval(this.transportInterval) @@ -35,7 +48,7 @@ export default { clearInterval(this.timeRemainingInterval) this.timeRemaining = 0 }, - timer() { + startTimer() { this.timeRemaining -= 1 } },