music-parser
Music notation parser. It takes an string and returns an array of objects with the form { value: '', position: 0, duration: 0}
. You can parse durations or measures or a combination of both:
var parse = ;;;;
It is agnostic about the value of the object. It only take cares about the duration, either by explicit duration (using /
) or by dividing the measure length between the number of events.
This is used by ScoreJS to parse music.
Installation
Install the npm module: npm install --save music-parser
, and require the library:
var parse = ;
Usage
You can parse a string separated by |
...
;// [{ value: 'Cm', position: 0, duration: 1 },// { value: 'D0', position: 1, duration: 0.5 },// { value: 'G7', position: 1.5, duration: 0.5 },// { value: 'Cm', position: 2, duration: 1 }]
You can specify durations:
var melody = ;// [{ value: 'a2', position: 0, duration: 0.25 },// { value: 'b2', position: 0.25, duration: 0.25 },// { value: 'c#3', position: 0.5, duration: 0.125 },// { value: 'd3', position: 0.625, duration: 0.125 }]
The duration can be expressed with numbers and dots ("4."
, "2.."
), with
letters and dots ("q."
, "w.."
) or names ("quarter"
). See note-duration
If the duration is not specified, and there's no measure separator, the default duration is 4. But if there are any measure separators, the duration is calculated by dividing the measure length by the number of items. You can use parenthesis to group items and write complex rhythmic structures:
; // duration: 0.25, 0.25, 0.25, 0.25; // durations: 0.5, 0.25, 0.25; // durations: q, q, qt, qt, qt // durations: 0.375, 0.125, 0.25, 0.25
The _
symbol extends the duration of the previous item:
parser'Cm | _ ');// [{ value: 'Cm', position: 0, duration: 2 }];// [{ value: 'c', position: 0, duration: 0.25 }]// [{ value: 'd', position: 0.25, duration: 0.50 }]// [{ value: 'e', position: 0.75, duration: 0.25 }]// [{ value: 'f', position: 1, duration: 0.75 }]// [{ value: 'g', position: 1.75, duration: 0.25 }]
You can specify other time signatures (it's 4/4 by default):
;;
Dependencies
It uses time-meter to time signature operations.
It uses note-duration to parse durations.
License
MIT License