Import Tone object

This commit is contained in:
Kevin Thomas
2022-04-15 16:01:40 -07:00
parent bfb0891844
commit 0a6bf8b44d

View File

@@ -1,4 +1,4 @@
import { Filter, LFO, Noise, Player, Players, Transport, Tremolo } from 'tone' import * as Tone from 'tone'
export default { export default {
name: 'Noise', name: 'Noise',
@@ -90,12 +90,12 @@ export default {
} }
}, },
created () { created () {
this.noise = new Noise() this.noise = new Tone.Noise()
this.filter = new Filter() this.filter = new Tone.Filter()
this.tremolo = new Tremolo() this.tremolo = new Tone.Tremolo()
this.lfo = new LFO() this.lfo = new Tone.LFO()
this.players = new Players() this.players = new Tone.Players()
this.samplePreviewPlayer = new Player().toDestination() this.samplePreviewPlayer = new Tone.Player().toDestination()
this.samplePreviewPlayer.loop = true this.samplePreviewPlayer.loop = true
this.populateProfileItems(0) this.populateProfileItems(0)
@@ -113,28 +113,28 @@ export default {
} }
this.playDisabled = true this.playDisabled = true
Transport.cancel() Tone.Transport.cancel()
if (!this.isFilterEnabled && !this.isTremoloEnabled) { if (!this.isFilterEnabled && !this.isTremoloEnabled) {
this.noise = new Noise({ volume: this.volume, type: this.noiseColor }).toDestination() this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).toDestination()
} else if (!this.isFilterEnabled && this.isTremoloEnabled) { } else if (!this.isFilterEnabled && this.isTremoloEnabled) {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.noise = new Noise({ volume: this.volume, type: this.noiseColor }).connect(this.tremolo) this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.tremolo)
} else if (this.isFilterEnabled && !this.isTremoloEnabled) { } else if (this.isFilterEnabled && !this.isTremoloEnabled) {
this.filter = new Filter(this.filterCutoff, this.filterType).toDestination() this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination()
this.noise = new Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter)
} else if (this.isFilterEnabled && this.isTremoloEnabled) { } else if (this.isFilterEnabled && this.isTremoloEnabled) {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.filter = new Filter(this.filterCutoff, this.filterType).connect(this.tremolo) this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo)
this.noise = new Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter)
} else { } else {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.filter = new Filter(this.filterCutoff, this.filterType).connect(this.tremolo) this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo)
this.noise = new Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter) this.noise = new Tone.Noise({ volume: this.volume, type: this.noiseColor }).connect(this.filter)
} }
if (this.isLFOFilterCutoffEnabled) { if (this.isLFOFilterCutoffEnabled) {
this.lfo = new LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] })
this.lfo.connect(this.filter.frequency).start() this.lfo.connect(this.filter.frequency).start()
} }
@@ -150,7 +150,7 @@ export default {
if (this.isTimerEnabled) { if (this.isTimerEnabled) {
this.duration = parseInt((this.hours * 3600)) + parseInt((this.minutes * 60)) + parseInt(this.seconds) this.duration = parseInt((this.hours * 3600)) + parseInt((this.minutes * 60)) + parseInt(this.seconds)
this.noise.sync().start(0).stop(this.duration) this.noise.sync().start(0).stop(this.duration)
Transport.loopEnd = this.duration Tone.Transport.loopEnd = this.duration
this.timeRemaining = this.duration this.timeRemaining = this.duration
this.transportInterval = setInterval(() => this.stop(), this.duration * 1000 + 100) this.transportInterval = setInterval(() => this.stop(), this.duration * 1000 + 100)
this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000) this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000)
@@ -166,11 +166,11 @@ export default {
}) })
} }
Transport.start() Tone.Transport.start()
}, },
stop () { stop () {
clearInterval(this.transportInterval) clearInterval(this.transportInterval)
Transport.stop() Tone.Transport.stop()
this.playDisabled = false this.playDisabled = false
clearInterval(this.timeRemainingInterval) clearInterval(this.timeRemainingInterval)
@@ -210,27 +210,27 @@ export default {
if (!this.isFilterEnabled && !this.isTremoloEnabled) { if (!this.isFilterEnabled && !this.isTremoloEnabled) {
this.noise.toDestination() this.noise.toDestination()
} else if (!this.isFilterEnabled && this.isTremoloEnabled) { } else if (!this.isFilterEnabled && this.isTremoloEnabled) {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.noise.connect(this.tremolo) this.noise.connect(this.tremolo)
} else if (this.isFilterEnabled && !this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) { } else if (this.isFilterEnabled && !this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) {
this.filter = new Filter(this.filterCutoff, this.filterType).toDestination() this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination()
this.noise.connect(this.filter) this.noise.connect(this.filter)
this.lfo.disconnect() this.lfo.disconnect()
this.lfo.stop() this.lfo.stop()
} else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) { } else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && !this.isTremoloEnabled) {
this.filter = new Filter(this.filterCutoff, this.filterType).toDestination() this.filter = new Tone.Filter(this.filterCutoff, this.filterType).toDestination()
this.noise.connect(this.filter) this.noise.connect(this.filter)
this.lfo = new LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] })
this.lfo.connect(this.filter.frequency).start() this.lfo.connect(this.filter.frequency).start()
} else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && this.isTremoloEnabled) { } else if (this.isFilterEnabled && this.isLFOFilterCutoffEnabled && this.isTremoloEnabled) {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.filter = new Filter(this.filterCutoff, this.filterType).connect(this.tremolo) this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo)
this.noise.connect(this.filter) this.noise.connect(this.filter)
this.lfo = new LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] }) this.lfo = new Tone.LFO({ frequency: this.lfoFilterCutoffFrequency, min: this.lfoFilterCutoffRange[0], max: this.lfoFilterCutoffRange[1] })
this.lfo.connect(this.filter.frequency).start() this.lfo.connect(this.filter.frequency).start()
} else { } else {
this.tremolo = new Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start() this.tremolo = new Tone.Tremolo({ frequency: this.tremoloFrequency, depth: this.tremoloDepth }).toDestination().start()
this.filter = new Filter(this.filterCutoff, this.filterType).connect(this.tremolo) this.filter = new Tone.Filter(this.filterCutoff, this.filterType).connect(this.tremolo)
this.noise.connect(this.filter) this.noise.connect(this.filter)
} }
}, },