Closer to our goal
This commit is contained in:
parent
8a31150c1a
commit
bb354fc4f8
|
@ -1,27 +1,29 @@
|
||||||
const socket = io();
|
const socket = io()
|
||||||
|
|
||||||
import { NOTE, SPACE } from "./settings.js"
|
|
||||||
|
|
||||||
import { pick } from "./modules/utils.js"
|
import { pick } from "./modules/utils.js"
|
||||||
|
|
||||||
|
import { NOTE, SPACE, RECORDING } from "./settings.js"
|
||||||
|
|
||||||
import { amsynth } from "./modules/instruments/amsynth.js"
|
import { amsynth } from "./modules/instruments/amsynth.js"
|
||||||
import { duosynth } from "./modules/instruments/duosynth.js"
|
import { duosynth } from "./modules/instruments/duosynth.js"
|
||||||
import { monosynth } from "./modules/instruments/monosynth.js"
|
import { monosynth } from "./modules/instruments/monosynth.js"
|
||||||
import { membranesynth } from "./modules/instruments/membranesynth.js"
|
import { membranesynth } from "./modules/instruments/membranesynth.js"
|
||||||
import { plucksynth } from "./modules/instruments/plucksynth.js"
|
import { plucksynth } from "./modules/instruments/plucksynth.js"
|
||||||
|
|
||||||
const instrument = pick([amsynth, duosynth, monosynth, membranesynth, plucksynth])
|
|
||||||
|
|
||||||
import { reverb } from "./modules/effects/reverb.js"
|
import { reverb } from "./modules/effects/reverb.js"
|
||||||
|
|
||||||
Tone.Transport.bpm.value = 60;
|
// Pick an instrument
|
||||||
|
const instrument = pick([amsynth, duosynth, monosynth, membranesynth, plucksynth])
|
||||||
|
|
||||||
// A channel to chain instruments and effects
|
// A channel to chain instruments and effects
|
||||||
const channel = new Tone.Channel();
|
const channel = new Tone.Channel()
|
||||||
|
|
||||||
// This is a hack to have something running, which makes the reverb work
|
// This is a hack to have something running, which makes the reverb work
|
||||||
const pingpong = new Tone.PingPongDelay({delayTime : 2, feedback : 0, wet : 0})
|
const pingpong = new Tone.PingPongDelay({delayTime : 2, feedback : 0, wet : 0})
|
||||||
|
|
||||||
|
// A filter
|
||||||
|
const filter = new Tone.Filter({type:"lowpass", frequency:800})
|
||||||
|
|
||||||
// Chain the channel and effects to the master out
|
// Chain the channel and effects to the master out
|
||||||
channel.connect(pingpong)
|
channel.connect(pingpong)
|
||||||
pingpong.connect(reverb)
|
pingpong.connect(reverb)
|
||||||
|
@ -35,28 +37,107 @@ voice.playbackRate = 0.75
|
||||||
voice.loop = true
|
voice.loop = true
|
||||||
voice.autostart = false
|
voice.autostart = false
|
||||||
|
|
||||||
|
const noise = new Tone.Noise("brown")
|
||||||
|
noise.connect("channel")
|
||||||
|
|
||||||
let playloop = undefined
|
let playloop = undefined
|
||||||
|
|
||||||
const pathway = pick([0, 1, 2])
|
const pathway = pick([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
|
||||||
|
|
||||||
const play = () => {
|
const play = () => {
|
||||||
// Determine which of our patterns to play
|
// Determine which of our patterns to play
|
||||||
switch(pathway) {
|
switch(pathway) {
|
||||||
case 0:
|
case 0:
|
||||||
|
const autoFilter = new Tone.AutoFilter("3m", "200", 3.6).start()
|
||||||
|
const cChord = ['C4', 'E4', 'G4', 'B4']
|
||||||
|
const dChord = ['D4', 'F4', 'A4', 'C5']
|
||||||
|
const gChord = ['B3', 'D4', 'E4', 'A4']
|
||||||
|
|
||||||
|
const piano = new Tone.PolySynth(Tone.Synth, {
|
||||||
|
oscillator: {
|
||||||
|
partials: [3, 2, 1]
|
||||||
|
},
|
||||||
|
volume: -9
|
||||||
|
}).connect(autoFilter)
|
||||||
|
|
||||||
|
autoFilter.connect(channel)
|
||||||
|
|
||||||
|
const pianoPart = new Tone.Part({
|
||||||
|
callback: (time, chord) => {
|
||||||
|
piano.triggerAttackRelease(chord, '8n', time)
|
||||||
|
},
|
||||||
|
events: [
|
||||||
|
['0:0:2', cChord],
|
||||||
|
['0:1', cChord],
|
||||||
|
['0:1:3', dChord],
|
||||||
|
['0:2:2', cChord],
|
||||||
|
['0:3', cChord],
|
||||||
|
['0:3:2', gChord]
|
||||||
|
],
|
||||||
|
loop: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
const interval = pick(["5m", "6m", "7m"])
|
||||||
|
|
||||||
|
const schedule = Tone.Transport.scheduleRepeat((time) => {
|
||||||
|
pianoPart.stop()
|
||||||
|
pianoPart.start()
|
||||||
|
}, interval, "0")
|
||||||
|
|
||||||
|
break
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
playloop = new Tone.Player("/static/recordings/" + RECORDING).connect(channel)
|
||||||
|
playloop.loop = true
|
||||||
|
playloop.autostart = true
|
||||||
|
break
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
playloop = new Tone.Player("/static/recordings/" + RECORDING).connect(channel)
|
||||||
|
playloop.loop = true
|
||||||
|
playloop.autostart = true
|
||||||
|
break
|
||||||
|
|
||||||
|
case 3:
|
||||||
playloop = new Tone.Loop((time) => {
|
playloop = new Tone.Loop((time) => {
|
||||||
instrument.triggerAttackRelease(NOTE, "16n")
|
instrument.triggerAttackRelease(NOTE, "16n")
|
||||||
}, SPACE).start(0)
|
}, SPACE).start(0)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 1:
|
case 4:
|
||||||
|
playloop = new Tone.Loop((time) => {
|
||||||
|
instrument.triggerAttackRelease(NOTE, "16n")
|
||||||
|
}, SPACE).start(0)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
playloop = new Tone.Loop((time) => {
|
||||||
|
instrument.triggerAttackRelease(NOTE, "9n")
|
||||||
|
}, SPACE).start(0)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 6:
|
||||||
playloop = new Tone.Loop((time) => {
|
playloop = new Tone.Loop((time) => {
|
||||||
instrument.triggerAttackRelease(NOTE, "8n")
|
instrument.triggerAttackRelease(NOTE, "8n")
|
||||||
}, SPACE).start(0)
|
}, SPACE).start(0)
|
||||||
break
|
break
|
||||||
|
|
||||||
case 2:
|
case 7:
|
||||||
playloop = new Tone.Player("/static/recordings/birds.mp3").connect(channel)
|
playloop = new Tone.Loop((time) => {
|
||||||
playloop.loop = true
|
instrument.triggerAttackRelease(NOTE, "8n")
|
||||||
playloop.autostart = true
|
}, SPACE).start(0)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
playloop = new Tone.Loop((time) => {
|
||||||
|
instrument.triggerAttackRelease(NOTE, "6n")
|
||||||
|
}, SPACE).start(0)
|
||||||
|
break
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
playloop = new Tone.Loop((time) => {
|
||||||
|
instrument.triggerAttackRelease(NOTE, "6n")
|
||||||
|
}, SPACE).start(0)
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -66,19 +147,29 @@ const play = () => {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
socket.on('all_action', () => {
|
socket.on('all_action', () => {
|
||||||
console.log('ACTION')
|
|
||||||
document.body.style.background = "orange"
|
document.body.style.background = "orange"
|
||||||
voice.start()
|
voice.start()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
socket.on('all_noise', () => {
|
||||||
|
document.body.style.background = "black"
|
||||||
|
voice.stop()
|
||||||
|
noise.start()
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on('all_stop', () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
const flowers = ["🌼", "🌸", "💮", "🌺", "🪷", "🏵️"]
|
const flowers = ["🌼", "🌸", "💮", "🌺", "🪷", "🏵️"]
|
||||||
|
|
||||||
const playbutton = document.getElementById('play')
|
const playbutton = document.getElementById('play')
|
||||||
|
|
||||||
playbutton.addEventListener('click', () => {
|
playbutton.addEventListener('click', () => {
|
||||||
if (playbutton.className == 'paused') {
|
if (playbutton.className == 'paused') {
|
||||||
playbutton.className = 'playing';
|
playbutton.className = 'playing'
|
||||||
playbutton.innerHTML = pick(flowers);
|
playbutton.innerHTML = pick(flowers)
|
||||||
|
|
||||||
Tone.context.resume().then(() => {
|
Tone.context.resume().then(() => {
|
||||||
Tone.start()
|
Tone.start()
|
||||||
Tone.Transport.start("+0.1")
|
Tone.Transport.start("+0.1")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export const duosynth = new Tone.DuoSynth({
|
export const duosynth = new Tone.DuoSynth({
|
||||||
volume : -9
|
volume : -12
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import { pick } from "./modules/utils.js"
|
import { pick } from "./modules/utils.js"
|
||||||
|
|
||||||
export const NOTES = ["A3", "A2", "C4", "C3", "F3", "F2"]
|
const NOTES = ["A3", "A2", "C4", "C3", "F3", "F2"]
|
||||||
export const NOTE = pick(NOTES)
|
export const NOTE = pick(NOTES)
|
||||||
|
|
||||||
export const SPACING = ["7h", "8h", "9h", "10h"]
|
const SPACING = ["7h", "8h", "9h", "10h"]
|
||||||
export const SPACE = SPACING[Math.floor(Math.random() * SPACING.length)]
|
export const SPACE = pick(SPACING)
|
||||||
|
|
||||||
|
const RECORDINGS = ["birds.mp3", "stairs.mp3"]
|
||||||
|
export const RECORDING = pick(RECORDINGS)
|
||||||
|
|
||||||
|
Tone.Transport.bpm.value = 60;
|
||||||
|
|
BIN
static/recordings/stairs.mp3
Normal file
BIN
static/recordings/stairs.mp3
Normal file
Binary file not shown.
|
@ -2,22 +2,51 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf8" />
|
<meta charset="utf8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Admin</title>
|
<title>Admin</title>
|
||||||
<style>
|
<style>
|
||||||
|
html, body {
|
||||||
|
padding : 0;
|
||||||
|
margin : 0;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
background : #222;
|
background : #222;
|
||||||
color : #aaa;
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-size : 2em;
|
||||||
|
padding : 1em;
|
||||||
|
margin : 1em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<button id="action">Action</button>
|
<button id="action">Action</button>
|
||||||
|
<button id="noise">Noise</button>
|
||||||
|
<button id="stop">Stop</button>
|
||||||
<script src="static/js/lib/socket.io.js"></script>
|
<script src="static/js/lib/socket.io.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const socket = io();
|
const socket = io();
|
||||||
|
|
||||||
document.getElementById('action').addEventListener('click', () => {
|
document.getElementById('action').addEventListener('click', () => {
|
||||||
socket.emit('action')
|
socket.emit('action')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
document.getElementById('noise').addEventListener('click', () => {
|
||||||
|
socket.emit('noise')
|
||||||
|
})
|
||||||
|
|
||||||
|
document.getElementById('stop').addEventListener('click', () => {
|
||||||
|
socket.emit('stop')
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue