Key Concepts

Quick and dirty documentation for TinyRave. I strongly suggest coding with the TinyRave package for Atom.

TinyRave looks for two special functions when running your track: buildSample or buildTrack. A track should define either buildSample, OR buildTrack, but not both.

Most public methods use named parameters. Instead of parseMidi(myTransport, myParts) you would write parseMidi({transport: myTransport, parts: myParts}).

Mixables

A mixable is any function that takes a time in seconds and returns a sample value. E.g.:

var mixable = function(time) { return Math.sin(TWO_PI * A_4 * time); }

Mixables generate audio samples. All process() functions in the Instruments library accept a mixable, and return a new mixable. buildSample() is itself a mixable.

buildSample

The easiest way to generate audio. Define a function named buildSample, which accepts a time value and returns a sample. If defined TinyRave will call this function 44,100 times a second.

Usage

// JavaScript Example
var buildSample = function(time){
  return Math.sin(TWO_PI * A_4 * time);
}
# CoffeeScript Example
buildSample = (time) ->
  Math.sin TWO_PI * A_4 * time

buildTrack

The more powerful, but more advanced, way to compose tracks. Define a buildTrack function and it will run in the scope of a small DSL for scheduling events.

If defined, this function runs once.

You can call the following special methods in the body of your buildTrack function to schedule events and add mixables to the global mixer:

  • this.every(interval, callback)
  • this.until(duration, callback)
  • this.after(delay, callback)
  • this.play(mixable)

And configure your environment:

  • this.setMasterGain(gain)
  • this.setBPM(bpm)

Technically we run any function named buildTrack in the scope of a BuildTrackEnvironment instance from the Standard Library.

Usage

// JavaScript Example
var buildTrack = function(){
  this.every(1, function(){
    // Every second ...
    var o = new Oscillator;
    var e = new Envelope;
    var mixable = e.process(o);

    // Add mixable to the global mixer
    this.play(mixable);
  });
}
# CoffeeScript Example
buildTrack = ->
  @every 1, ->
    o = new Oscillator
    e = new Envelope
    mixable = e.process(o)
    @play mixable

Libraries

TinyRave provides two external libraries for added functionality. The adapter and standard library, included in all tracks by default, are open source.

Adapter.js

Imported by default. Allows communication between a track and its host.

View Source

Documentation

StdLib.coffee

Imported by default. Tools to schedule events, along with note frequency definitions.

View Source

Documentation

Instruments.coffee

Optional. Oscillator, Filter, Envelope and Mixer classes. Higher-level abstractions for building music.

Import with require('v1/instruments')

View Source

Documentation

Midi.coffee

Optional. An adapter for the JSON structures generated by an online MIDI converter: MidiConvert

Import with require('v1/midi')

View Source

Documentation

results matching ""

    No results matching ""