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

genonamestr-pmb

v0.1.1

Published

Parser for the genonamestr music notation format. Allows to express a melody as a human-readable text.

Downloads

8

Readme

genonamestr-pmb

Parser for the genonamestr music notation format. Allows to express a melody as a human-readable text.

Purpose: I needed a method to store a melody in a text file, so my first idea was to just write the note names. In school I learned the German names, so in genonamestr the pinao key left of C is called H, not B.

The name is just an abbreviation for "GErman NOte NAmes MElody STRing".

API

This module exports one function:

parseGeNoNaMeStr(melody[, opt])

Translates a string melody into an array of music events, with optional options object opt.

Supported options, and their defaults:

  • octaveOffset (integer, default: 0): Which octave the note names refer to. Zero means Helmholtz pitch notation, so uppercase C means MIDI note 36, lowercase c means MIDI note 48.
  • noteDura (float, default: some small number): Default duration for how long a note is to be played, in seconds.
  • noteGapFrac (float, default: some small number): Default duration for a pause (silence) after each note, in units of 1 noteDura.
  • parseLimit (integer, default: 0): How many melody parts to parse. Zero means "all parts".
  • volume (float, default: 1): Initial volume, as a fraction [0..1].

The melody string may consist of any combination of:

  • Whitespace: Space, Tab, CR, LF. They're ignored.
  • Note name: Any letter A-H or a-h, optionally followed by # (U+0023 number sign).
    • Grammar-wise, a number sign is allowed after any of these letters, but the parser will only accept it for C, D, F and G, because the other combinations can be expressed with just letters: E#F, A#B, B#H, H#c, etc.
    • There's a special additional note name ¢ (U+00A2 cent sign) which is just above h (initially, MIDI note 60). There's no ¢#.
    • There's a special additional note name , (U+002C comma) which is silent, so it's a pause.
    • Duration of a note can be extended by appending and an optional number num to its name. num can be integer or float, and it cannot have a sign or an exponent. If num is missing or zero, it defaults to 1. The note duration will be extended by num units of noteDura, so its effective duration should be (num+1) * noteDura. This has no effect on noteGapFrac calculations.
  • Comment: A number sign (#) that isn't part of a note name, followed by any amount of characters that are not U+000A line feed. Comments are ignored.
  • Number tweak: A tweak marker (listed below), optionally followed by a number num. (Sign optional, decimal point optional, no exponent.) If the number is omitted, 0 (zero) is assumed, and for some tweaks, zero means to use the default value. Supported tweak markers:
    • <: Move note name range num octaves to the left (lower pitch). (default: 1)
    • >: Move note name range num octaves to the right (higher pitch). (default: 1)
    • <>: Reset the note name range to Helmholtz, then move it num octaves to the right (higher pitch).
    • ~: Set noteDura to num seconds. (default: default noteDura)
    • : Multiply noteDura by num. (default: 1)
    • ~…: Set noteGapFrac to num.
    • ^: Set volume to num.
    • : Multiply volume by num.

Usage

from test/usage.js:

var genonamestr = require('genonamestr-pmb'), melody,
  cN = 'note', cP = 'pause', cG = 0.125;

melody = '~0.25 ~…0.5 Ba…, ^.5 C…2h,… >>h ^×.5<>h ^<>-1h';
equal.lists(genonamestr(melody), [
  { t: cN, name: 'B', midiKey: 47,  dura: 0.25, vol: 1,     gap: cG },
  { t: cN, name: 'a', midiKey: 57,  dura: 0.5,  vol: 1,     gap: cG },
  { t: cP,                          dura: 0.25,             gap: cG },
  { t: cN, name: 'C', midiKey: 36,  dura: 0.75, vol: 0.5,   gap: cG },
  { t: cN, name: 'h', midiKey: 59,  dura: 0.25, vol: 0.5,   gap: cG },
  { t: cP,                          dura: 0.5,              gap: cG },
  { t: cN, name: 'h', midiKey: 83,  dura: 0.25, vol: 0.5,   gap: cG },
  { t: cN, name: 'h', midiKey: 59,  dura: 0.25, vol: 0.25,  gap: cG },
  { t: cN, name: 'h', midiKey: 47,  dura: 0.25, vol: 0,     gap: cG },
]);

Known issues

  • needs more/better tests and docs

 

License

ISC