abudaan / heartbeat

a javascript MIDI/Audio sequencer for your browser
http://abudaan.github.io/heartbeat/
120 stars 20 forks source link

heartbeat

important update 19/12/2020

Heartbeat will no longer be maintained here it its own repository because heartbeat is now part of WebDAW modules. You can still use heartbeat like before but you have to import it to your project from webdaw-modules, see below.

introduction

Heartbeat is a MIDI/Audio sequencer for your browser. Heartbeat has no GUI. It is intended to be used as an engine behind your application. Heartbeat is set up very flexible so you can make any kind of application on top of it; a game, an online DAW, artistic sites, music science experiments and so on. Read more.

So far heartbeat has been used in 2 MusicFirst projects:

example

Install heartbeat: yarn add webdaw-modules

or: npm i webdaw-modules

import { heartbeat, Heartbeat } from 'webdaw-modules';

const init = async () => {
  await heartbeat.ready();

  const events: Heartbeat.MIDIEvent[] = heartbeat.util.getRandomNotes({
      minNoteNumber: 60,
      maxNoteNumber: 100,
      minVelocity: 30,
      maxVelocity: 80,
      numNotes: 60
  });

  const part: Heartbeat.Part = heartbeat.createPart();
  part.addEvents(events);

  const song: Heartbeat.Song = heartbeat.createSong({
    parts: part,
    useMetronome: true
  });

  document.addEventListener('click', () => {   
    if (song.isPlaying) {
      song.pause();
    } else {
      song.play();
    }
  });
}

init();

So heartbeat (all lowercase) is the module and Heartbeat (with capital) is the namespace where all heartbeat typings live.

Obviously you don't have to use typescript and you can use in your plain javascript projects as well.

Another example if you don't want to use async await and prefer to keep using the name sequencer instead of heartbeat:

import { heartbeat as sequencer } from 'heartbeat-sequencer';

sequencer
.ready()
.then(init);

const init = () => {
  const events = sequencer.util.getRandomNotes({
    minNoteNumber: 60,
    maxNoteNumber: 100,
    minVelocity: 30,
    maxVelocity: 80,
    numNotes: 60
  });

  const part = sequencer.createPart();
  part.addEvents(events);

  const song = sequencer.createSong({
    parts: part,
    useMetronome: true
  });

  document.addEventListener('click', () => {   
    if (song.isPlaying) {
      song.pause();
    } else {
      song.play();
    }
  });
}

key features

MIDI
Audio
Instruments

More documentation can be found here.