Repository navigation
Expand file tree
/
Copy pathjazz.js
More file actions
36 lines (31 loc) · 1.68 KB
/
Copy pathjazz.js
File metadata and controls
36 lines (31 loc) · 1.68 KB
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
// Generative jazz — a style, a lead, a key, and a new performance every time.
// Run: node examples/jazz.js
// Run: node examples/jazz.js style=ambient lead=flute -d 3m
// Keys: space pause · q quit
import { AudioContext } from 'web-audio-api'
import { init } from './graphs/jazz.js'
import { args, sec, keys, clearLine, help } from './utils.js'
help({
description: 'generate a jazz performance in a chosen style',
usage: ['', 'style=ambient lead=flute -d 3m', 'style=bossa bpm=124'],
options: [
['style=<name>', 'modal (default), ambient, nordic, ballad, bossa, swing, or blues'],
['lead=<name>', 'flute (default), guitar, harp, or piano'],
['bpm=<number>', 'performance tempo (default: the middle of the style\'s range)'],
['-d, --duration <time>', 'target length with optional s/m/h suffix (default: 270s)'],
],
controls: [['Space', 'pause/resume'], ['Q / Esc', 'quit']],
notes: ['Every performance picks a new key, tempo, and improvisation; pass seed=<number> to repeat one.'],
})
let { $ } = args()
let style = String($('style', 'modal')).toLowerCase()
let lead = String($('lead', 'flute')).toLowerCase()
let bpm = $('bpm') ? +$('bpm') : null
let seed = $('seed') ? +$('seed') : null
let dur = sec($('dur', '270'))
let ctx = new AudioContext()
await ctx.resume()
let demo = await init(ctx, { style, lead, bpm, seed, duration: dur })
keys({}, () => { clearLine(); ctx.close() }, ctx)
console.log(`♪ ${demo.data.style} in ${demo.data.key}, ${demo.data.lead} lead, ${demo.data.bpm} BPM, ${(demo.duration / 60).toFixed(1)} min — space pause · q quit\n` + demo.data.chordLog.join(' '))
setTimeout(() => { clearLine(); ctx.close(); process.exit(0) }, demo.duration * 1000 + 500)