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:
- Lisp as a second language, composing programs and music: http://www.mcg.uva.nl/papers/lisp2nd/functional.pdf
- Haskell School of Music: http://www.cs.yale.edu/homes/hudak/Papers/HSoM.pdf
Example
// require the libraryvar score = // create the scorevar song = // play the score:// create an audio contextvar ac = // require the player modulevar player = player // show the score in a piano roll// given a canvas...var ctx = canvas// require the pianoroll modulevar pianoRoll = pianoRoll
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:
// a melodyvar seq = score// a chordvar chord = score
The phrase
and chord
functions are helpers to write the above more concisely:
var seq = scorevar chord = score
You can combine elements freely:
// the melody and the chord simultaneouslyvar song = score
Finally, you can use a valid JSON data to define scores:
var song =
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)