Add dark mode, allow noise settings to be changed while running, add timer toggle

This commit is contained in:
Kevin Thomas
2021-07-19 01:35:52 -07:00
parent bca1faebbb
commit 5585d81690
5 changed files with 73 additions and 27 deletions

View File

@@ -1,23 +1,26 @@
<template> <template>
<v-app> <v-app>
<v-main> <v-main>
<AppBar />
<Noise /> <Noise />
</v-main> </v-main>
</v-app> </v-app>
</template> </template>
<script> <script>
import Noise from './components/Noise'; import Noise from './components/Noise'
import AppBar from './components/AppBar'
export default { export default {
name: 'App', name: 'App',
components: { components: {
AppBar,
Noise, Noise,
}, },
data: () => ({ data: () => ({
// //
}), }),
}; }
</script> </script>

16
src/components/AppBar.vue Normal file
View File

@@ -0,0 +1,16 @@
<template>
<v-app-bar
app
color="secondary"
dark
dense
>
<v-container fill-height>
<v-switch
v-model="$vuetify.theme.dark"
inset
label="Dark Mode"
/>
</v-container>
</v-app-bar>
</template>

View File

@@ -37,6 +37,20 @@
Stop Stop
</v-btn> </v-btn>
<v-checkbox
v-model="isTimerEnabled"
:disabled="startDisabled"
label="Enable Timer"
class="mx-3"
/>
<v-text-field
v-model="noiseDuration"
label="Seconds"
class="mx-3"
:disabled="startDisabled || !isTimerEnabled"
/>
<v-text-field <v-text-field
v-model="timeRemaining" v-model="timeRemaining"
class="mx-3" class="mx-3"
@@ -44,6 +58,7 @@
label="Time Remaining" label="Time Remaining"
filled filled
readonly readonly
:disabled="!isTimerEnabled"
/> />
</v-row> </v-row>
</v-col> </v-col>
@@ -54,18 +69,15 @@
</h2> </h2>
<v-row justify="center"> <v-row justify="center">
<v-text-field <v-slider
v-model="noiseVolume" v-model="noiseVolume"
label="Volume" label="Volume"
thumb-label="always"
:thumb-size="40"
max="0"
min="-30"
class="mx-3" class="mx-3"
:disabled="startDisabled" @change="updateVolume"
/>
<v-text-field
v-model="noiseDuration"
label="Seconds"
class="mx-3"
:disabled="startDisabled"
/> />
<v-select <v-select
@@ -73,7 +85,7 @@
:items="noiseColorOptions" :items="noiseColorOptions"
label="Noise Color" label="Noise Color"
class="mx-3" class="mx-3"
:disabled="startDisabled" @change="updateNoiseColor"
/> />
</v-row> </v-row>
</v-col> </v-col>
@@ -86,13 +98,13 @@
<v-row justify="center"> <v-row justify="center">
<v-checkbox <v-checkbox
v-model="isFilterEnabled" v-model="isFilterEnabled"
:disabled="startDisabled"
label="Enabled" label="Enabled"
class="mb-5" class="mb-5"
:disabled="startDisabled"
/> />
</v-row> </v-row>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-row justify="center"> <v-row justify="center">
<v-select <v-select
@@ -100,9 +112,9 @@
:items="filterTypeOptions" :items="filterTypeOptions"
label="Filter Type" label="Filter Type"
class="mx-3" class="mx-3"
:disabled="!isFilterEnabled ||startDisabled" :disabled="!isFilterEnabled || startDisabled"
/> />
<v-slider <v-slider
v-model="frequencyCutoff" v-model="frequencyCutoff"
label="Frequency Cutoff (Hz)" label="Frequency Cutoff (Hz)"

View File

@@ -5,7 +5,8 @@ export default {
data: () => ({ data: () => ({
startDisabled: false, startDisabled: false,
noiseDuration: 4, isTimerEnabled: false,
noiseDuration: 60,
timeRemaining: 0, timeRemaining: 0,
noiseColorOptions: ["pink", "white", "brown"], noiseColorOptions: ["pink", "white", "brown"],
noiseColor: "pink", noiseColor: "pink",
@@ -13,32 +14,39 @@ export default {
isFilterEnabled: false, isFilterEnabled: false,
frequencyCutoff: 20000, frequencyCutoff: 20000,
filterTypeOptions: ["lowpass", "highpass", "bandpass", "lowshelf", "highshelf", "notch", "allpass", "peaking"], filterTypeOptions: ["lowpass", "highpass", "bandpass", "lowshelf", "highshelf", "notch", "allpass", "peaking"],
filterType: "lowpass" filterType: "lowpass",
rules: {
number: value => !isNaN(parseInt(value, 10)) || 'Invalid number',
negative: value => (!isNaN(parseInt(value, 10)) && value <= 0) || "Can't be greater than 0"
}
}), }),
created() { created() {
this.noise = new Noise() this.noise = new Noise()
this.filter = new Filter()
}, },
methods: { methods: {
playNoise() { playNoise() {
this.startDisabled = true this.startDisabled = true
Transport.cancel() Transport.cancel()
this.filter = new Filter(this.frequencyCutoff, this.filterType).toDestination()
if (this.isFilterEnabled) { if (this.isFilterEnabled) {
this.filter = new Filter(this.frequencyCutoff, this.filterType).toDestination()
this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).connect(this.filter) this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).connect(this.filter)
} else { } else {
this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).toDestination() this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).toDestination()
} }
this.noise.sync().start(0).stop(this.noiseDuration)
if (this.isTimerEnabled) {
this.noise.sync().start(0).stop(this.noiseDuration)
Transport.loopEnd = this.noiseDuration
this.timeRemaining = this.noiseDuration
this.transportInterval = setInterval(() => this.stopTransport(), this.noiseDuration * 1000 + 100)
this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000)
} else {
this.noise.sync().start(0)
}
Transport.start() Transport.start()
Transport.loopEnd = this.noiseDuration
this.transportInterval = setInterval(() => this.stopTransport(), this.noiseDuration * 1000 + 100)
this.timeRemaining = this.noiseDuration
this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000)
}, },
stopTransport() { stopTransport() {
clearInterval(this.transportInterval) clearInterval(this.transportInterval)
@@ -50,6 +58,12 @@ export default {
}, },
startTimer() { startTimer() {
this.timeRemaining -= 1 this.timeRemaining -= 1
},
updateVolume() {
this.noise.volume.value = this.noiseVolume
},
updateNoiseColor() {
this.noise.type = this.noiseColor
} }
}, },
} }

View File

@@ -4,4 +4,5 @@ import Vuetify from 'vuetify/lib/framework';
Vue.use(Vuetify); Vue.use(Vuetify);
export default new Vuetify({ export default new Vuetify({
theme: { dark: false },
}); });