91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
const socket = io();
|
|
|
|
import { NOTE, SPACE } from "./settings.js"
|
|
|
|
import { pick } from "./modules/utils.js"
|
|
|
|
import { amsynth } from "./modules/instruments/amsynth.js"
|
|
import { duosynth } from "./modules/instruments/duosynth.js"
|
|
import { monosynth } from "./modules/instruments/monosynth.js"
|
|
import { membranesynth } from "./modules/instruments/membranesynth.js"
|
|
import { plucksynth } from "./modules/instruments/plucksynth.js"
|
|
|
|
const instrument = pick([amsynth, duosynth, monosynth, membranesynth, plucksynth])
|
|
|
|
import { reverb } from "./modules/effects/reverb.js"
|
|
|
|
Tone.Transport.bpm.value = 60;
|
|
|
|
// A channel to chain instruments and effects
|
|
const channel = new Tone.Channel();
|
|
|
|
// This is a hack to have something running, which makes the reverb work
|
|
const pingpong = new Tone.PingPongDelay({delayTime : 2, feedback : 0, wet : 0})
|
|
|
|
// Chain the channel and effects to the master out
|
|
channel.connect(pingpong)
|
|
pingpong.connect(reverb)
|
|
reverb.connect(Tone.Master)
|
|
|
|
// Chain instrument to the channel
|
|
instrument.connect(channel)
|
|
|
|
const voice = new Tone.Player("/static/recordings/tts.mp3").connect(channel)
|
|
voice.playbackRate = 0.75
|
|
voice.loop = true
|
|
voice.autostart = false
|
|
|
|
let playloop = undefined
|
|
|
|
const pathway = pick([0, 1, 2])
|
|
const play = () => {
|
|
// Determine which of our patterns to play
|
|
switch(pathway) {
|
|
case 0:
|
|
playloop = new Tone.Loop((time) => {
|
|
instrument.triggerAttackRelease(NOTE, "16n")
|
|
}, SPACE).start(0)
|
|
break
|
|
|
|
case 1:
|
|
playloop = new Tone.Loop((time) => {
|
|
instrument.triggerAttackRelease(NOTE, "8n")
|
|
}, SPACE).start(0)
|
|
break
|
|
|
|
case 2:
|
|
playloop = new Tone.Player("/static/recordings/birds.mp3").connect(channel)
|
|
playloop.loop = true
|
|
playloop.autostart = true
|
|
break
|
|
|
|
default:
|
|
// Defaulting
|
|
}
|
|
}
|
|
|
|
(function() {
|
|
socket.on('all_action', () => {
|
|
console.log('ACTION')
|
|
document.body.style.background = "orange"
|
|
voice.start()
|
|
})
|
|
|
|
const flowers = ["🌼", "🌸", "💮", "🌺", "🪷", "🏵️"]
|
|
|
|
const playbutton = document.getElementById('play')
|
|
|
|
playbutton.addEventListener('click', () => {
|
|
if (playbutton.className == 'paused') {
|
|
playbutton.className = 'playing';
|
|
playbutton.innerHTML = pick(flowers);
|
|
Tone.context.resume().then(() => {
|
|
Tone.start()
|
|
Tone.Transport.start("+0.1")
|
|
}).then(
|
|
play()
|
|
)
|
|
}
|
|
})
|
|
})()
|