hum-drum
A small framework for playing music using the Web Audio API
Last updated 2 years ago by bl-rd .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hum-drum 
SYNC missed versions from official npm registry.

Hum-drum

Little library for generating music using the WebAudio API. Doesn't do anything special (in fact there are a lot better versions of things like this out there) but this was a good learning excerise. I created this for my JS13K 2017 game (which I never finished ????)

Disclaimer: still a work in progress!

Example usage

import HumDrum from 'hum-drum';

/**
 * 100 bpm
 * 16 ticks per look
 */
let track = new HumDrum(100, 16);

// create the drun track
let snare = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0];
let bass =  [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
let hh =    [0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0];
let data = {
    snare: snare,
    bass: bass,
    hiHat: hh
}

let midNotes =  ['c',  '', '',  '', '',  '',   'a#', 'c',  '',   'f', 'g', 'a#', 'c', 'g', '',  ''];
let bassNotes = ['c', 'c', 'c', '', 'c', 'a#', 'a#', 'a#', 'a#', '',  'c', 'a#', 'f', 'f', 'f', 'f'];

track
    // key, data, start, loop
    .addDrumTrack('drums', data, 0, true, true)
    // key, data, start, loop, pitch
    .addSynthTrack('bass', bassNotes, 0, true, 2)
    .addSynthTrack('mid', midNotes, 0, true, 6)
    .play();

window.addEventListener('humdrumTick' e => {
    let tick = e.detail.tick;
    if (tick % 8 === 0) {
        track.muteTrack('mid');
    }
    if (tick === 0) {
        track.unMuteTrack('mid');
    }
});

Current Tags

  • 0.1.1                                ...           latest (2 years ago)

5 Versions

  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 2
Last Month 0
Dependencies (2)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |