Chorus.js: Music Composition in JavaScript
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
- If you want real-time MIDI output, follow node-gyp's installation instructions
- Otherwise, ignore non-fatal errors during installation. You can still use MIDI file output
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
Run
node simple-song.js -f simple-song.mid
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
- Download SimpleSynth and launch it
- Select
MIDI Source: SimpleSynth virtual input
Run the Chorus examples and select
simplesynth
as the port.node simple-song.js -p simplesynth
Windows
Run the Chorus.js examples and select
Microsoft GS Wavetable Synth
as the port.node simple-song.js -p wavetable
Tutorials
Work in progress!
- Inter-App MIDI - how to connect to DAWs or standalone synthesizer apps
- Rhythm - how to organize time
- Pitch & Harmony - how to organize pitch
- Song Structure - how to organize song structure
- Advanced Features - how to avoid repetition and create variety
- Microtonality - how to use more than 12 pitches per octave
- Under the Hood - how to hack on chorus.js