Home

Chorus.js: Music Composition in JavaScript

npm version    build status    test coverage

Features

  • Compose music with Node.js
  • Harmony-based sequencing using scales and chord progressions
  • Multitrack MIDI output
    • real-time MIDI - control MIDI instruments like synthesizers
    • MIDI files - capture musical ideas for later use
  • Microtonal support

Browser support is planned at some point.

Requirements

  • Node.js v6 or higher
  • Optional: compilation tools for native dependencies

Installation

  npm install chorus

Note: If you setup the native dependencies for real-time MIDI output after installation, you must reinstall chorus.

Quick Start Guide

Chorus.js (currently) does not make any sound on it's own. It outputs MIDI, a standard format for controlling music software & hardware. Let's see how it works.

Create the file simple-song.js in the folder where you installed chorus:

// simple-song.js
const { Song, Output } = require('chorus');
require('chorus/names').into(global);

const song = new Song({
  sections: [{
    parts: [{
      pitches: [C4, D4, E4, F4, G4, F4, E4, D4, C4],
    }]
  }]
});

Output.select().then(output => output.play(song));

Don't worry if this doesn't make sense yet. We'll explore everything in the tutorials below.

NOTE: require('chorus/names').into(global) adds global constants, so we can write C4 instead of PITCHES.C4. This is convenient but potentially dangerous, and not recommended in complex projects that combine chorus.js with other libraries. The Under the Hood tutorial will explain how to avoid this. For now, let's continue...

Output.select() allows us to choose real-time or file output. To see usage instructions, run it:

    node simple-song.js

Let's take a look at our output options.

MIDI File Output

  1. Run

     node simple-song.js -f simple-song.mid
  2. Open (or drag and drop) simple-song.mid to an app that supports MIDI playback, such as a DAW


For example (assuming you have not changed the default file associations on your OS):

  • macOS: Double-click a .mid file (or run open simple-song.mid in the Terminal) to open in Garage Band and play it
  • Windows: TODO

Real-time MIDI Output

NOTE: Real-time output requires an optional native dependency to be installed, as explained in the requirements above. If you have trouble installing that, you can use MIDI file output instead.

macOS

  1. Download SimpleSynth and launch it
  2. Select MIDI Source: SimpleSynth virtual input
  3. Run the Chorus examples and select simplesynth as the port.

     node simple-song.js -p simplesynth

Windows

  1. Run the Chorus.js examples and select Microsoft GS Wavetable Synth as the port.

     node simple-song.js -p wavetable

Tutorials

Work in progress!

  1. Inter-App MIDI - how to connect to DAWs or standalone synthesizer apps
  2. Rhythm - how to organize time
  3. Pitch & Harmony - how to organize pitch
  4. Song Structure - how to organize song structure
  5. Advanced Features - how to avoid repetition and create variety
  6. Microtonality - how to use more than 12 pitches per octave
  7. Under the Hood - how to hack on chorus.js

Project Info