Tuesday, December 12, 2006

How can I create my own custom language to generate timed events? ( Part I )

The synthmaker parsing components allow for a custom language to be defined and actions to be taken controlled by the parsed text.

Defining a syntax

I'll start with a very simple example. The following schematic defines a syntax of the letter N followed by an Integer number, followed by a comma , followed by a real number, followed by another comma, followed by another real number.

That syntax is defined by the components str>>int>>str>>real>>str>>real. The str components have an input to specify which exact string has to be matched. The int and real components output the parsed numbers. An example of a valid syntax would be:

N60,2,3

The CustomParse component outputs a boolean to indicate if the parsed text has the correct syntax. It also has an input to trigger the actual parsing. To trigger the parsing all you have to do is click on the middle red square of the trigger button

Zero or more matches

Now if you try the following text:

N60,2,3 N64,1,2

the custom parser will fail giving a wrong syntax error as shown in the following screen capture:

That's because the syntax has been defined for 1 and only 1 match. To specify that we want several possible matches of our syntax we have to use the Kleene Star rule which means zero or more matches. The new schematic would be as follows:

Now we have a custom language with a simple syntax. In the next part I'll show how to convert those instructions into actions that generate Midi events.