Reset start button when noise ends, add remaining time display

This commit is contained in:
Kevin Thomas
2021-07-18 13:57:50 -07:00
parent 51f6165412
commit e5ff566165

View File

@@ -17,35 +17,62 @@
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-btn <h2 class="headline font-weight-bold mb-5">
:disabled="isDisabled" Playback
@click="handleStart" </h2>
>
Start <v-row justify="center">
</v-btn> <v-btn
:disabled="startDisabled"
class="mx-3"
@click="handleStart"
>
Start
</v-btn>
<v-btn
class="mx-3"
@click="stopTransport"
>
Stop
</v-btn>
<v-text-field
v-model="timeRemaining"
class="mx-3"
:value="timeRemaining"
label="Time Remaining"
filled
readonly
/>
</v-row>
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<v-btn <h2 class="headline font-weight-bold mb-5">
@click="handleStop" Noise Settings
> </h2>
Stop
</v-btn>
</v-col>
<v-col cols="12"> <v-row justify="center">
<v-text-field <v-text-field
v-model="noiseDuration" v-model="noiseVolume"
label="Seconds" label="Volume"
/> class="mx-3"
</v-col> />
<v-col cols="12"> <v-text-field
<v-select v-model="noiseDuration"
v-model="noiseColor" label="Seconds"
:items="noiseColorOptions" class="mx-3"
label="Noise Color" />
/>
<v-select
v-model="noiseColor"
:items="noiseColorOptions"
label="Noise Color"
class="mx-3"
/>
</v-row>
</v-col> </v-col>
</v-row> </v-row>
</v-container> </v-container>
@@ -58,25 +85,39 @@
name: "Noise", name: "Noise",
data: () => ({ data: () => ({
isDisabled: false, startDisabled: false,
noiseDuration: 4, noiseDuration: 4,
timeRemaining: 0,
noiseColorOptions: ["pink", "white", "brown"], noiseColorOptions: ["pink", "white", "brown"],
noiseColor: "pink" noiseColor: "pink",
noiseVolume: -10
}), }),
created() { created() {
this.noise = new Noise()
}, },
methods: { methods: {
handleStart() { handleStart() {
this.isDisabled = true this.startDisabled = true
Transport.cancel() Transport.cancel()
this.noise = new Noise({volume: -10, type: this.noiseColor}).toDestination() this.noise = new Noise({volume: this.noiseVolume, type: this.noiseColor}).toDestination()
this.noise.sync().start(0).stop(this.noiseDuration) this.noise.sync().start(0).stop(this.noiseDuration)
Transport.start() Transport.start()
Transport.loopEnd = this.noiseDuration Transport.loopEnd = this.noiseDuration
this.transportInterval = setInterval(() => this.stopTransport(), this.noiseDuration * 1000 + 100)
this.timeRemaining = this.noiseDuration
this.timeRemainingInterval = setInterval(() => this.timer(), 1000)
}, },
handleStop() { stopTransport() {
clearInterval(this.transportInterval)
Transport.stop() Transport.stop()
this.isDisabled = false this.startDisabled = false
clearInterval(this.timeRemainingInterval)
this.timeRemaining = 0
},
timer() {
this.timeRemaining -= 1
} }
}, },
} }