1.1.0 • Published 10 years ago

mml-iterator v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

mml-iterator

Build Status NPM Version License

MML(Music Macro Language) Iterator

Installation

$ npm install mml-iterator

API

MMLIterator

  • constructor(source: string)

Instance methods

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

Example

import MMLIterator from "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
  • r(\d+)?\.*
    • 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

1.1.0

10 years ago

1.0.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago