OpenMusic

Visual Programming | Computer-Assisted Composition

Navigation : Previous | Next

Designing an Iterative Process with the File-Box

Contents

  1. Getting Results : Finally
  2. InitDo : Performing Initial Operations
  3. Eachtime : Repeating an Operation
  4. File-Box inputs

All the common OMloop tools - iterators, accumulators - can be used in the File-Box to design iterative file read/write processes.

Getting Results : Finally

Just like in an OMLoop, the Finally box allows to return something as a result of the iteration.

Example : Returning a Pathname

Pathnames can be returned at the end of a process, which is quite convenient when writing a file.

—|—

The file can be accessed and used in a program.

Here, the file pathname allows to load and visualize the written file in a TextFile object.

Visualizing the resulting text in a textfile box – above – and in the
textfile editor – below.

Visualizing the resulting text in a textfile box - above - and in the textfile editor - below.

—|—

InitDo : Performing Initial Operations

The InitDo box is called internally, just after the filestream has been initialized, and before the iteration starts.

It allows to perform initial operations, such as writing a “file header”, as in this example.

Example : Writing a Header

Here, an Initdo module has been added to the program, so that a text header is added before the strings.

The data printed by InitDo is visible in the text file.

—|—

Eachtime : Repeating an Operation

Eachtime allows to execute an operation at each step of the loop. can be used for writing data in the file at each step of the loop.

Example : Writing Several Lines of Strings

—|—

The text file can be visualized in a textfile box.

—|—

File-Box inputs

The content of the file and other parameters - the file pathname for instance

Inputs are added or removed like in OMLoop boxes : press alt + -> or <-.

Here, File-Box writes a text file that contains ten lines with “hello”. The internal program of FileBox allows to add a header to the text, and a number to each line.

—|—

The pathname returned by Finally can possibly be displayed in a text- view .

The content of the text displayed in the textfile box shows :

References :

Contents :

Navigation : Previous | Next