Rhythm.js

This module is a IIFE (Immediately Invoked Function Expression) and it returns a var with the name of Rhythm. This document contains its public API. The Rhythm module contains functions used to manipulate and translate Rhythms into different formats used with Tone.js

It will merge parallel arrays of notes, durations and velocities into an array of objects for use with the Tone.js

Also adds some support functions for the PlayRhythm page in the PracticeRoom app

Rhythm.js
Example
use the script tag to add this file
<script src="path/to/Rhythm.js"></script>

setDurationString

this stores the duration and noteNames on the Rhythm object

setDurationString(durationString: string, noteNames: string, whichVoice: number)
Parameters
durationString (string)
noteNames (string)
whichVoice (number)

setOnlyDurationString

this stores the duration on the Rhythm object

setOnlyDurationString(durationString: string, whichVoice: number)
Parameters
durationString (string)
whichVoice (number)

mergeRhythmAndPitch

this function merges two arrays into a single array of objects used by Tone.js

mergeRhythmAndPitch(rhythms: string, pitches: string): object
Parameters
rhythms (string)
pitches (string)
Returns
object: the merged data

processDurationNotation

this function takes an array of duration notation and creates an array of cummlative values used by Tone.js

processDurationNotation(duration_array: object, startTime: number): object
Parameters
duration_array (object) (array of strings)
startTime (number)
Returns
object: the array of cummlative values in seconds

mergeDurationsAndPitch

this function merges two arrays into a single array of objects used by Tone.js

mergeDurationsAndPitch(durations: object, pitches: object, startTime: string): object
Parameters
durations (object) (array of strings)
pitches (object) (array of strings)
startTime (string) (optional)
Returns
object: the merged data
Example
parameters: durations, ptiches
var durations = ['4n','8n','8n','4n+8n','8n'];
var pitches = ['A4','C5','C#5','E5','G#4'];
var noteObjects = mergeDurationsAndPitch(durations, pitches, '0');
// array of noteObjects (with three attributes) used in Tone.Part(function(time, value){ }, noteObjects );
  time = t_array[i] - returned from processDurations(durations)
  note  = pitches[i]
  duration = durations[i]

  NOTE:  The note and duration are unpacked in the callback function as value.note and value.duration
         and are used as parameter to the function 
         synth.triggerAttackRelease(value.note, value.duration, time)

mergeDurationVelocityAndPitch

this function merges three arrays into a single array of objects used by Tone.js

mergeDurationVelocityAndPitch(durations: object, pitches: object, velocity: object, startTime: string): object
Parameters
durations (object) (array of strings)
pitches (object) (array of strings)
velocity (object) (optional) default = 0.7 (1.0 max) (array of numbers)
startTime (string) (optional)
Returns
object: the merged data

getTotalTime

this function return the total time of the currently stored durations

getTotalTime(): string
Returns
string: totalTime