09.12.2012 Views

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

The Kyma Language for Sound Design, Version 4.5

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

You can assign values to Smalltalk variables using the := assignment operator. For example, in the following<br />

Script,<br />

| curTime curFreq |<br />

curTime := 0.<br />

curFreq := 100.<br />

curTime is assigned the value 0 and curFreq is set to the value 100.<br />

Additional kinds of Smalltalk variables (called block arguments and block temporaries) are described in<br />

<strong>The</strong> Smalltalk-80 <strong>Language</strong> on page 513.<br />

TextFileInterpreter Messages<br />

A TextFileInterpreter (a version of the Script <strong>Sound</strong>) reads data from text files. You can use a TextFileInterpreter<br />

to read and interpret scores written <strong>for</strong> a Music–N language. More generally, you can use a<br />

TextFileInterpreter to map any data to sound parameters.<br />

In addition to allowing you to use general Smalltalk messages, a TextFileInterpreter also lets you use the<br />

following specialized messages <strong>for</strong> accessing text files:<br />

Smalltalk Message Result<br />

atEnd Returns true if at the end of the file, or false if not at the end.<br />

linesInFile Returns the number of lines in the text file.<br />

maxValue Returns the largest number in the file. If there are no numbers in the file,<br />

maxValue returns -∞.<br />

minValue Returns the smallest number in the file. If there are no numbers in the file, min-<br />

Value returns +∞.<br />

nextNumber Returns the next number. Returns 0 at the end of the file or at a letter.<br />

nextParameters Returns the entire next line as an Array. Each item on the line that is separated by<br />

a space is put into a separate entry in the Array.<br />

reset Moves to the beginning of the file.<br />

In the script of a TextFileInterpreter, you refer to the text file by the name file. You can address the file<br />

in its entirety, asking file <strong>for</strong> the number of lines it has and <strong>for</strong> its maximum and minimum values. For<br />

example, the following statements assign the largest value in the file to the Smalltalk variable max, the<br />

smallest value to min, and the number of lines to lines:<br />

| max min lines |<br />

max := file maxValue.<br />

min := file minValue.<br />

lines := file linesInFile.<br />

You can also access the data in the file one line at a time. In the following statements, the Smalltalk variable<br />

dataArray is assigned an array containing each value found on the next line of the disk file:<br />

| dataArray |<br />

dataArray := file nextParameters.<br />

<strong>The</strong> TextFileInterpreter keeps track of the last line it read from the file, so you can continue to read the<br />

“next” line until you reach the end of the file. To start over again at the beginning of a file, reset the file by<br />

using<br />

file reset.<br />

in the Script.<br />

529

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!