Variable declaration is the same as in C:
When you declare a variable you must specify its type.
More than one variable of the same type can be declared in the same declaration.
A variable's value may be set when it's declared.
The variable declaration statement takes the following form:
dataType identifier [ = expression ] [ , identifier [ = expression ] ] ... ; |
Assignment is also like C:
identifier = expression |
Variable assignments can be nested and can appear in parameter value expressions.
ScoreFile provides seven data types:
double
int
string
env
wave
object
var
The double and int types are the same as in C; string takes a string value:
string = "text"; |
env, wave, and object take MKEnvelope, MKWaveTable, and object values, respectively, as described in the following sections. var is a wild card: A variable so declared automatically matches the type of its assigned data. In general, var obviates the need for the other six types; however, the others can be used for clarity, or to cast a value to a particular type.
You can create an MKEnvelope in a scorefile by using an envelope statement:
envelope envelopeName = envelopeConstant ; |
When the scorefile is read, an MKEnvelope object is created and named for each envelope statement in the file. envelopeName can be any previously undeclared identifier and can be used as the value in a variable assignment (the variable's type must be env or var):
env = envelopeName ; |
envelopeConstant contains a list of the MKEnvelope's breakpoints. Each breakpoint is described by its x, y, and (optional) smoothing values. Breakpoint descriptions are in parentheses and the entire MKEnvelope is delimited by brackets:
[ ( xValue , yValue [ , smoothingValue ] ) , ... ] |
A scorefile can contain any number of MKEnvelopes.
MKWaveTables are created with the waveTable statement:
waveTable waveTableName = waveTableConstant ; |
Similar to the envelope statement, an object is created and named for each waveTable statement in a scorefile when the file is read. The created object is either a MKPartials or a MKSamples object, depending on the specification in waveTableConstant. A MKPartials object is described as a series frequency ratio, amplitude ratio, and (optional) phase values.
Each specification defines a single partial and is surrounded by braces; like an MKEnvelope, the entire object is delimited by brackets:
[ { frequencyRatio , amplitudeRatio [ , phase ] } , ... ] |
A MKSamples object is defined by a soundfile:
[ { "soundfileName" } ] |
waveTableName can be used in a wave or var assignment.
You can use an object statement to add your own objects to a scorefile:
object objectName = objectConstant ; |
objectConstant contains, in brackets, the name of the object's class followed by a description of the object:
[ className objectDescription ] |
objectDescription can be any text except “]”. className must implement the methods readASCIIStream:, and writeASCIIStream: to define how to read and write the object description.
When an include statement is encountered, the specified file is immediately read and interpreted:
include "scorefileName"; |
A print statement is used to print information to a stream pointer (NXStream *):
print expression [ , expression ] ... ; |
The information is displayed when the scorefile is interpreted. The setScorefilePrintStream: method, defined by MKScore and MKScorefilePerformer, lets you set the stream to which a scorefile's messages are printed. By default, they're printed to standard error.
The tune statement lets you create a tuning system other than the default twelve-tone equal-temperament:
tune pitchVariable = expression ; |
tune expression ; |
The first form of the statement tunes pitchVariable, a predeclared ScoreFile variable, to expression, taken as a frequency in hertz. All pitch variables of the same pitch class as pitchVariable are tuned to the appropriate octave transposition of expression. Pitch variables are described in the Section called Predeclared Variables, Constants, and Special Symbols. The second form transposes all pitch variables by expression half-steps. A negative value transposes down; a fractional value transposes by less than a half step.