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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@errozero/beatstepper

v1.1.1

Published

This is a webaudio event scheduler inspired by the article: https://html5rocks.com/en/tutorials/audio/scheduling/

Downloads

4

Readme

Beatstepper

This is a webaudio event scheduler inspired by the article: https://html5rocks.com/en/tutorials/audio/scheduling/

Supports different time divisions: 4/4 or 3/4 for example.

Usage

Install Beatstepper: npm install @errozero/beatstepper

Create an instance and pass in a web audio context, and a callback function:

import { Beatstepper, IBeatstepperCallbackData } from '@errozero/beatstepper';

const ctx = new AudioContext();
const callback = (data:IBeatstepperCallbackData) => {
	console.log('Step!', data);
};

const beatstepper= new Beatstepper(ctx, callback);

Now that is setup, call the start method to begin scheduling:

beatstepper.start()

This will run at the default tempo of 130bpm, with 4/4 time division.

Your callback function will run on every step and receive an object with the following structure:

{
	step: number, //The current step, starting at 0, default max is 15
	beat: number, //The current beat, starts at 0, default max is 3
	bar: number, //Current bar, starts at 0, default max is 3
	startTime: number, //The webaudio clock time that events for this step should start
	stepLength: number //Calculated length of one step, useful for sub-step timing
}

Your callback function could be used to trigger notes or samples from a pattern array etc.

Methods

start
Starts the clock

beatstepper.start();


stop
Stops the clock and resets the current step, beat and bar to 0

beatstepper.stop();


pause
Pauses the clock

beatstepper.pause();


setTempo
Sets the tempo in bpm

Param: tempo:number

beatstepper.setTempo(160);


setStepsPerBeat
Sets the number of steps that make up a beat, default is 4. This works together with beatsPerBar to set the timing of the clock. It represents the first 4 in 4/4.

Param: steps:number

beatstepper.setStepsPerBeat(4);


setBeatsPerBar
Sets the number of beats that make up a bar. This works together with stepPerBeat to set the timing of the clock. It represents the second 4 in 4/4.

Param: beats:number

beatstepper.setBeatsPerBar(4);

Metronome example

import { Beatstepper, IBeatstepperCallbackData } from '@errozero/beatstepper';

const context = new AudioContext();
const stepsPerBeat = 4;
const tempo = 90;

const  callback = (data:IBeatstepperCallbackData) => {
	const  freq = (data.step % stepsPerBeat == 0) ? 880 : 440;
	const  oscillator = context.createOscillator();
	oscillator.type = 'square';
	oscillator.frequency.setValueAtTime(freq, context.currentTime); // value in hertz
	oscillator.connect(context.destination);
	oscillator.start(data.startTime);
	oscillator.stop(data.startTime + (data.stepLength/2));
}

const  beatstepper = new  Beatstepper(context, callback);

beatstepper.setTempo(tempo);
beatstepper.setStepsPerBeat(stepsPerBeat);

beatstepper.start();