0.10.0 • Published 8 years ago

scorejs v0.10.0

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

ScoreJS

Build Status CodeClimate js-standard-style

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

// 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)

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 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]
)

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)