rhythm-math
v1.0.0
Published
Rhythm mathematics for the browser and web audio — tempo, polyrhythm, groove, syncopation, and meter
Maintainers
Readme
rhythm-math
Rhythm mathematics for the browser and web audio — tempo, polyrhythm, groove, syncopation, and meter.
Install
npm install rhythm-mathAPI
Types
Tempo—{ bpm: number }Polyrhythm—{ rates: number[] }Groove—{ velocities: number[], offsets: number[] }Meter—{ numerator: number, denominator: number }
Tempo
bpmToMs(bpm)→ milliseconds per beatmsToBpm(ms)→ BPMtempoCurve(start, end, steps, curve)→number[]where curve is"linear","exponential", or"logarithmic"
Polyrhythm
polyrhythmCycleLength(rates)→ LCM of ratespolyrhythmPattern(rates)→ binary arrays per voicepolyrhythmDensity(rates)→ average hit density
Groove
swingFactor(grid, amount)→ swung grid positionsgrooveVelocity(pattern, accents?)→ MIDI velocities (0–127)microtiming(offsets, humanize)→ humanized offsets
Syncopation
syncopationScore(pattern, meterNumerator)→ Longuet-Higgins/Lee scoreoffbeatDensity(pattern, meterNumerator)→ fraction of off-beat hitsrhythmicEntropy(pattern)→ Shannon entropy of interval distribution
Meter
isSimple(meter),isCompound(meter),isOdd(meter)→ booleanbeatCount(meter)→ main beats per measuresubdivision(meter)→ subdivisions per beatdownbeats(measures, meter)→ downbeat positionstimeSignatureChanges(meters, repeats?)→ expanded meter sequence
License
MIT
