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

rhythmically

v0.2.1

Published

Create musical sequences easily

Downloads

6

Readme

Rhythmically

Create musical sequences with javascript. Rhythmically parses a string with optional durations, and returns an array of objects in the form: { value: '', position: 0, duration: 0 } ordered by position.

var r = require('rhythmically');
var s = r.sequence('a/q b/q c/e');
// [{ value: 'a', position: 0, duration: 0.25 }
//  { value: 'b', position: 0.25, duration: 0.25 }
//  { value: 'c', position: 0.5, duration: 0.125 }]

Rhythmically uses note-duration to convert from duration names ('quarter', 'whole', 'q.') to duration values. You can also use numbers (c2/4 means a C at 2 octave with quarter length).

It is agnostic about the content of the event (the value). It only cares about durations and positions:

var s = r.sequence('Cm/d Dm/w G7/w');
// [{ value: 'Cm', position: 0, duration: 2}]
//  { value: 'Dm', position: 2, duration: 1}]
//  { value: 'G7', position: 3, duration: 1}]

## Usage

Add the module to your project npm i --save rhythmically and require it:

var r = require('rhythmically');

## API

Rhythmically.sequence(source [, transform] [, options])

Returns an array of objects where value, position and duration are always defined (the first as string, the others as numbers).

The durations are expressed in musical names ('whole', 'eight') and separated by a /. If no duration given, 1/4 is the default. This can be customized with a options.parseDuration function (see options below).

The source can be a string or an array:

s1 = r.sequence('c d');
// [{ value: 'c', position: 0, value: 0.25 },
//  { value: 'd', position: 0.25, value: 0.25 }]
s2 = r.sequence(['c', 'd']);
// s2 is equal to s1

By default, events with value equal to 'r' are treated as rests:

s = r.sequence('a r/w b');
// [{ value: 'a', position: 0, value: 0.25},
//  { value: 'b', position: 1, value: 0.25}]

You can change the rest event value with the options.

Transformations

The transform is an optional function that is used to modify the events.
For example, used in combination with note-pitch:

var pitch = require('note-pitch');

s = r.sequence('c d e', function(event) {
  event.value = pitch.transpose(event.value, 'M2');
});
// [{ value: 'd', position: 0, duration: 0.25}
//  { value: 'e', position: 0.25, duration: 0.25}
//  { value: 'f#', position: 0.5, duration: 0.25}]

You can use it to transform previously parsed sequences:

var original = r.sequence('c d e');
var delayed = r.sequence(original, function(event) {
  event.position += 0.25;
});
var combined = r.merge(original, delayed);

Options

The following options are accepted:

  • restValue: the value of the events to be treated as rest. 'r' by default.
  • parseDuration: a function that parses a string and returns [value, duration] array
function parser(value) {
  var match = /^([a-z]+)\{(\d+)\}$/.exec(value);
  return [match[1], +match[2]];
}
r.sequence("a{10} rest{5} b{15}", null, { restValue: 'rest', parseDuration: parser });
// [{ value: 'a', position: 0,    duration: 10 },
//  { value: 'b', position: 15,   duration: 15 }]

### Rhythmically.duration(seq)

Return the total duration of a sequence array

Rhythmically.merge(seq1, seq2 [, seq3, ...])

Merges the given sequences:

r.merge(r.sequence('a b'), r.sequence('c d'));
// [{ value: 'a', position: 0,    duration: 0.25 },
//  { value: 'c', position: 0,    duration: 0.25 },
//  { value: 'b', position: 0.25, duration: 0.25 },
//  { value: 'd', position: 0.25, duration: 0.25 }]

Rhythmically.concat(seq1, seq2 [, seq3, seq4, ...])

Concatenates the given sequences:

r.concat(r.sequence('a b'), r.sequence('c d'));
// [{ value: 'a', position: 0,    duration: 0.25 },
//  { value: 'b', position: 0.25,    duration: 0.25 },
//  { value: 'c', position: 0.50, duration: 0.25 },
//  { value: 'd', position: 0.75, duration: 0.25 }]

License

MIT License