lilyPondAdapter.js

This module is a IIFE (Immediately Invoked Function Expression) and it returns a var with the name of lpAdapter. This document contains its public API. The lilyPondAdapter.js module contains functions used to translate from lilypond format to Tone.js and vice versa.

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

setScoreParameters

this sets the score values on the lilyPondAdapter object

setScoreParameters(json: object): any
Parameters
json (object)
Returns
any: nothing
Example
// an example of the json parameter
var jsonConfig = {
    "jsonType": "ScaleAssignment",
	"keySig": "c \\major",
	"clef": "treble",
	"timeSig": "4/4",
	"title": "Assignment",
	"name": "Assignment on "+timeStamp,
	"notes": notes,
	"durations": durations,
	"pickup": "",
	"pickupLength": "",
	"tempo": ' \"moderato\" 4 = 90',
	"opus": assignmentNumber,
	"composer": studentName
};
lpAdapter.setScoreParameters(jsonConfig);

setCPMelodyParameters

this sets the score values on the lilyPondAdapter object

setCPMelodyParameters(json: object): any
Parameters
json (object)
Returns
any: nothing
Example
// after the auto generated melody is created the following
// json is created as a parameter.
var jsonConfig = {
  "jsonType": "CPMelody",
 "keySig": keySig,
 "clef": clef,
 "timeSig": timeSig,
 "title": title,
 "name": title+" on "+timeStamp,
 "notes": notes,
 "durations": durations,
 "notes2": notes2,
 "durations2": durations2,
 "diceStaff": myOrnStaff,
 "pickup": pickup,
 "pickupLength": "",
 "tempo": tempo
};
lpAdapter.setCPMelodyParameters(jsonConfig);

setChoraleScoreParameters

this sets the chorale score values on the lilyPondAdapter object

setChoraleScoreParameters(json: object): any
Parameters
json (object)
Returns
any: nothing
Example
// example of json parameter for 4-part chorale
var jsonConfig = {
  "jsonType": "chorale",
  "keySig": keySig,
  "clef": clef,
  "timeSig": timeSig,
  "title": title,
  "name": title+" on "+timeStamp,
  "notes1": voicesNotesAndDurations[0][0].slice(),
  "durations1": voicesNotesAndDurations[0][1].slice(),

  "notes2": voicesNotesAndDurations[1][0].slice(),
  "durations2": voicesNotesAndDurations[1][1].slice(),

  "notes3": voicesNotesAndDurations[2][0].slice(),
  "durations3": voicesNotesAndDurations[2][1].slice(),

  "notes4": voicesNotesAndDurations[3][0].slice(),
  "durations4": voicesNotesAndDurations[3][1].slice(),

  "pickup": pickup,
  "pickupLength": "",
  "tempo": tempo
};
lpAdapter.setChoraleScoreParameters(jsonConfig);

setGrandStaffScoreParameters

this sets the grand staff score values on the lilyPondAdapter object

setGrandStaffScoreParameters(json1: object, json2: object): any
Parameters
json1 (object)
json2 (object)
Returns
any: nothing
Example
// example of json parameter for grand staff score
var json conFig = {
  "jsonType": "pianoCadence",
  "keySig": keySig,
  "clef": clef,
  "timeSig": timeSig,
  "title": title,
  "name": title+" on "+timeStamp,
  "notes1": LeftRightNotesAndDurations[0][0].slice(),
  "durations1": LeftRightNotesAndDurations[0][1].slice(),
  "notes2": LeftRightNotesAndDurations[1][0].slice(),
  "durations2": LeftRightNotesAndDurations[1][1].slice(),
  "pickup": pickup,
  "pickupLength": "",
  "tempo": tempo,
  "opus": assignmentNumber,
  "composer": studentName
}

createLilyPondFile

this function creates a lilypond file using the prevously save data

createLilyPondFile(evaluateBool: boolean): string
Parameters
evaluateBool (boolean) true includes an evaluation of the score compared to the correct answer
Returns
string: the lilypond file

translateLilyToToneJS

this function takes a lilypond string and turns it into two arrays of notes and durations used with ToneJS

translateLilyToToneJS(lilyNoteCode: string): object
Parameters
lilyNoteCode (string)
Returns
object: multi-dimensional array of notes and durations
Example
var lilycode = "\\relative c' {c4 d e f g1}";
var results = translateLilyToToneJS(lilycode);
// results[0] = ["C4","D4","E4","F4","G4"]
// results[1] = ["4n","4n","4n","4n","1n"]

getLilyEntryScoreParams

this function returns the keySig, tempo and timeSig from the lilyPondAdapter object

getLilyEntryScoreParams(): object
Returns
object: