npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

taktmuster

v1.2.0

Published

A project for generating and visualizing musical patterns

Readme

Taktmuster

taktmuster generates metrical patterns as both:

  • a discrete accent sequence like 4,1,2,1,3,1,2,1
  • a continuous curve you can iterate with getNext()

The project started as an experimental study around meter, curves, and pulse hierarchies. The current refactor keeps that idea, but reduces the API to a small deterministic core:

  • Taktmuster builds the pattern and curve
  • Metronome extends Taktmuster
  • every getNext() result includes timeoutMillis

Background

The library treats rhythm as layered structure.

  • Phrase layer: the whole span across all measures
  • Measure layer: the first beat of each measure
  • Group layer: internal beat groups such as 2+2 inside 4/4
  • Beat layer: the regular pulse grid
  • Subdivision layers: smaller internal steps when pulsePerQuarter is higher

This lets one object answer two different questions:

  • “What is the accent pattern?”
  • “What is the next timed curve sample?”

Modes

Taktmuster supports named strategies through type.

type: "balanced"

This is the default modern mode.

  • Uses phrase, measure, group, beat, and subdivision layers together
  • Produces a smoother normalized curve
  • Best for continuous modulation, visualization, and richer pulse density

Think of balanced as the more even, modern mathematical model.

type: "classic"

This mode is closer to the older metric hierarchy idea.

  • Builds accents from larger spans down to smaller spans
  • Keeps the hierarchy coarser
  • Produces stronger top-level accents with fewer internal layers

Think of classic as the more traditional accent-tree model.

Important: for some meters, the discrete beat pattern can be the same in classic and balanced, while the continuous curve is still different. The main difference is in how the curve layers are built.

Install

npm install

Usage

import { Taktmuster, Metronome } from 'taktmuster';

const tm = new Taktmuster({
  tempo: 120,
  pulsePerQuarter: 4,
  taktCnt: 2,
  zaehler: 4,
  nenner: 4,
  type: 'classic',
  curveType: 'cos'
});

console.log(tm.getTaktMuster());
// [4, 1, 2, 1, 3, 1, 2, 1]

const step = tm.getNext();
console.log(step);

Example getNext() payload:

{
  index: 0,
  cycle: 0,
  mode: 'classic',
  beatIndex: 0,
  stepInBeat: 0,
  patternValue: 4,
  waveformValue: 1,
  taktValue: 1,
  metricStrength: 2.36,
  timeoutMillis: 125,
  newCycle: false
}

Discrete Patterns

Use getTaktMuster() when you want the accent numbers directly.

new Taktmuster({
  taktCnt: 2,
  zaehler: 4,
  nenner: 4,
  type: 'classic'
}).getTaktMuster();
// [4, 1, 2, 1, 3, 1, 2, 1]

new Taktmuster({
  taktCnt: 2,
  zaehler: 3,
  nenner: 4,
  type: 'classic'
}).getTaktMuster();
// [3, 1, 1, 2, 1, 1]

Timed Iteration

getNext() returns the next sample and timeoutMillis.

const tm = new Taktmuster({
  tempo: 96,
  pulsePerQuarter: 4,
  taktCnt: 2,
  zaehler: 7,
  nenner: 8,
  type: 'balanced'
});

const next = tm.getNext();
console.log(next.timeoutMillis);

If you want automatic scheduling:

const stop = tm.notifyNext((step) => {
  console.log(step.index, step.timeoutMillis, step.patternValue);
});

// later
stop();

Metronome extends Taktmuster, so it can be used directly or mirror another instance:

const source = new Taktmuster({ taktCnt: 2, zaehler: 4, nenner: 4, type: 'classic' });
const metronome = new Metronome();
metronome.setTaktmuster(source);

API

new Taktmuster(options)

Main options:

  • tempo: BPM, default 120
  • pulsePerQuarter: pulses per quarter note, default 1
  • taktCnt: number of measures, default 1
  • zaehler: numerator, default 4
  • nenner: denominator, default 4
  • type: balanced or classic
  • curveType: cos, sin, or toggle
  • swing: alternating timing offset from -0.45 to 0.45
  • depth: optional subdivision depth override

Main methods:

  • setTempo(tempo, pulsePerQuarter)
  • setTakt(taktCnt, zaehler, nenner, curveType)
  • setType(type)
  • getCurve()
  • getTaktMuster()
  • getNext()
  • getNextTimeout()
  • notifyNext(callback, { immediate })
  • start(callback)
  • stop()
  • reset()
  • at(index)

Iteration Script

To inspect modes side by side, run:

npm run test:iterate

That script prints:

  • the discrete pattern
  • the first timed steps from getNext()
  • a side-by-side comparison of balanced and classic

Development

npm test
npm run test:iterate
npm run webpack:build
node index.node.js