Class: PLSystem

PLSystem()

This parametric Lindenmayer system for generating musical scores is defined as follows. See http://hardlikesoftware.com/projects/lsystem/lsystem.html. For the original definition of this type of system, see Przemyslaw Prusinkiewicz and Aristid Lindenmayer, The Algorithmic Beauty of Plants (New York: Springer Verlag, 1996 [1990]), pp. 40-50.

Name: JavaScript identifier.

Word: Text for a JavaScript expression consisting of a name, or a JavaScript function call with either formal or actual parameters, terminated with a semicolon, associated with a Command.

Production: A sequence of Words.

Command: A function that modifies the state of a Turtle; may be built-in or user-defined. A Word that is not assigned a Command is associated with a default builtin identity Command.

Turtle: An abstract pen that writes a musical score by performing the Commands in a Production.

Axiom: The initial Production of a Lindenmayer system, in which any parameters are actual.

Rule: A triple [Word, Condition, Production] in which any parameters may be actual or formal, or indeed any JavaScript expression.

Lindenmayer system: A set of Words, a set of associated Commands, an Axiom, one or more Rules, and a finite number N of Iterations. For each Word in the Axiom, the Axiom Word is replaced from the Rules; if the Axiom Word Name matches the Rule Word Name, and the Axiom Word parameters number the same as the Rule Word parameters, then if the Condition evaluates as true, the Rule Production replaces the Axiom Word after evaluating each Production Word's actual parameter expressions after substituting the Axiom Word's actual parameter values for any formal parameter names in the Production Word's actual parameter expressions; if as false, there is no Production; otherwise, the Axiom Word replaces itself. The resulting Production is taken as the Axiom for the next iteration. This is repeated N times. Then the final Production, consisting of a possibly long string of Words with only actual parameters, is evaluated.

Evaluation: The Command of each Word in the final Production is evaluated using the Turtle state and the Command with actual parameters, possibly causing the Turtle to write a musical score.

Note: The formal parameter names of the Word must be the same as the formal parameter names (after 'lsystem' and 'turtle') of the Word's Command (which is not a class member of the Word). The actual parameters of the Word may be values or unevaluated expressions; when the Command is called, the actual parameter expressions are evaluated using the actual parameter values of the parent Word as the values of the unevaluated parameters in the actual parameter expressions.

Example: Note(i,t,d,k,v,p) is replaced by Note(i2,t^1.1,d-1,k+3,v.9,p=Math.random()).

Reworked to use CsoundAC.PITV.