-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequencer1.ts
50 lines (42 loc) · 1015 Bytes
/
sequencer1.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { el } from '@elemaudio/core'
import { Track } from '../lib/base.js'
import { composePolySynth } from '../lib/elemaudio.js'
import { chord, midiToFc } from '../lib/music.js'
import { createSequencer, melodyToSeq } from '../lib/sequence.js'
import { InputType } from '../ui/input.jsx'
const notes = [
...chord('C-3', 'maj'),
null,
...chord('F-2', 'maj'),
null,
...chord('G-2', 'maj'),
null,
...chord('A-2', 'min'),
null,
]
const releaseTime = 0.5
const sequencer = createSequencer(
melodyToSeq(notes.map((n) => ({ data: n, duration: 1 }))),
{
initData: 0,
bpm: 140,
},
)
export default {
text: 'Sequence 1',
inputs: [{ type: InputType.TICK }],
renderAudio(inputs) {
const [tick] = inputs
const activeNotes = sequencer(tick)
if (activeNotes.length === 0) return 0
return el.mul(
composePolySynth(
activeNotes.map((n) => ({
env: el.adsr(0.1, 0.2, 0.6, releaseTime, n.triggerSignal),
sound: el.cycle(midiToFc(n.data)),
})),
),
0.7,
)
},
} as Track