ScoreJS

Work in progress
Create and manipulate musical scores with javascript. The aim of this project
is to provide a common interface and a high level toolkit that make easy
build useful tools for musicians.
This library is oriented to composition, music learning, score analysis or algorithmic composition. Even you can play music with it, it's not a sequencer or DAW type software.
This code is largely based in two papers:
## Example
var score = require('scorejs')
var song = score(
['melody', '4/4', 'c2 d2 e2 (f2 g2) | a2 b2 | c3'],
['harmony', '4/4', 'Cmaj7 | Dm7 G7 | Cmaj7']
)
var ac = new AudioContext()
var player = require('scorejs/ext/player')
player.play(ac, player.synth, score.tempo(120, song))
var ctx = canvas.getContext('2d')
var pianoRoll = require('scorejs/ext/pianoroll')
pianoRoll.draw(ctx, song)
Installation
Via npm package: npm i --save scorejs and require it:
var score = require('scorejs')
For browsers use the file in the dist folder:
Important:
It uses Object.assign so if your environment doesn't have it you need a polyfill, for example: https://github.com/sindresorhus/object-assign
Usage
scorejs models scores as collection of notes (objects with duration and pitch properties), that can be arranged sequentially o simultaneously:
var seq = score.seq(score.note(1, 'C'), score.note(1, 'D'), score.note(1, 'E'))
var chord = score.sim(score.note(3, 'C'), score.note(3, 'E'), score.note(3, 'G'))
The phrase and chord functions are helpers to write the above more concisely:
var seq = score.phrase('C D E', 1)
var chord = score.chord('C E G', 3)
You can combine elements freely:
var song = score.sim(
score.phrase('C D E', 1),
score.chord('C E G', 3)
)
Finally, you can use a valid JSON data to define scores:
var song = score(
['phrase', 'C D E', 1],
['chord', 'C E G', 3]
)
Play
There's a built-in scheduler and player based on Web Audio API.
Tests and examples
Clone this repo and install dependencies: npm install
Tests are executed with npm test
Examples can be running with beefy: npm -g install beefy and then: beefy example/pianoroll-example
License
The MIT License (MIT)