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 library
var score = require('scorejs')
// create the score
var song = score(
['melody', '4/4', 'c2 d2 e2 (f2 g2) | a2 b2 | c3'],
['harmony', '4/4', 'Cmaj7 | Dm7 G7 | Cmaj7']
)
// play the score:
// create an audio context
var ac = new AudioContext()
// require the player module
var player = require('scorejs/ext/player')
player.play(ac, player.synth, score.tempo(120, song))
// show the score in a piano roll
// given a canvas...
var ctx = canvas.getContext('2d')
// require the pianoroll module
var pianoRoll = require('scorejs/ext/pianoroll')
pianoRoll.draw(ctx, song)
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
scorejs
models scores as collection of notes (objects with duration
and pitch
properties), that can be arranged sequentially o simultaneously:
// a melody
var seq = score.seq(score.note(1, 'C'), score.note(1, 'D'), score.note(1, 'E'))
// a chord
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:
// the melody and the chord simultaneously
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]
)
There's a built-in scheduler and player based on Web Audio API.
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 examples/pianoroll-example
The MIT License (MIT)