/mml-iterator

MML(Music Macro Language) Iterator

Primary LanguageJavaScript

mml-iterator

Build Status NPM Version License

MML(Music Macro Language) Iterator

This is a fork of the (mml-iterator)[https://github.com/mohayonao/mml-iterator] by mohayonao, with some syntax extensions for greater compatibility with songs that can be found on the internet. Should be syntax backwards-compatible with the original, but it has been refactored into an ES module.

Installation

$ npm install @jstarpl/mml-iterator

API

MMLIterator

  • constructor(source: string)

Instance methods

  • next(): { done: boolean, value: object }
  • [Symbol.iterator]: self

Example

import MMLIterator from "@jstarpl/mml-iterator";

let iter = new MMLIterator("t200 o6 l8 e g > e c d g");

for (let noteEvent of iter) {
  console.log(noteEvent);
}
{ type: "note", time: 0.00, duration: 0.15, noteNumber:  88, velocity: 100, quantize: 75 }
{ type: "note", time: 0.15, duration: 0.15, noteNumber:  91, velocity: 100, quantize: 75 }
{ type: "note", time: 0.30, duration: 0.15, noteNumber: 100, velocity: 100, quantize: 75 }
{ type: "note", time: 0.45, duration: 0.15, noteNumber:  96, velocity: 100, quantize: 75 }
{ type: "note", time: 0.60, duration: 0.15, noteNumber:  98, velocity: 100, quantize: 75 }
{ type: "note", time: 0.75, duration: 0.15, noteNumber: 103, velocity: 100, quantize: 75 }
{ type: "end", time: 0.9 }

MML Syntax

NoteEvent

  • [cdefgab][-+]?(\d+)?\.*
    • note on (default: l)
    • e.g. c e-8. g16
  • [ ([cdefgab][-+]?|[<>])+ ](\d+)?\.*
    • chord (default: l)
    • e.g. [ >g<ce ]2 [ >gb<d ]2 [ >g<ce ]1
  • rp?\.*
    • rest (default: l)
    • e.g. l16 crcc crcc crccr crcc

NoteLength

  • l(\d+)?\.*
    • length (default: 4)
    • e.g. l8 cc l4 e l2 g
  • ^(\d+)?\.*
    • tie (default: l)
    • e.g l16 c^^ e^^ g^
  • q(\d+)?
    • quantize (default: 75)
    • e.g. l16 q50 crcc crcc crcc crcc

NotePitch

  • o(\d+)?
    • octave (default: 4)
    • e.g. o4 ceg o5 c
  • >(\d+)?
    • octave up (default: 1)
    • e.g. ceg < c
  • <(\d+)?
    • octave down (default: 1)
    • e.g. c > gec

Control

  • t(\d+)?
    • tempo (default: 120)
    • e.g. t140 cdefgab<c
  • v(\d+)?
    • velocity (default: 100)
    • e.g. v75 c v50 e v25 g
  • $
    • infinite loop
    • e.g. l2 $ [fa<ce] [gb<d] [egb<d] [ea<c]
  • /: ... | ... :/(\d+)?
    • loop (default: 2)
    • commands after | are skipped in the last loop
    • e.g. l2 /: [fa<ce] [gb<d] [egb<d] | [ea<c] :/4 [eg<c]

License

MIT