4.2 Sequencer
| Chapter 4. Controlling sound |

## 4.2 Sequencer

### 4.2.1 Theory

Instead of automatic processes, we can also write proper "scores" for a Pd patch. A simple example would be the use of many "send" commands, as described in 2.2.4.1.3:

But to be able to include much more information and determine the chronological sequence, the following section will cover ways to realize 'scores' in Pd.

#### 4.2.1.1 Text file

You can retrieve numbers and symbols from a normal text file or, conversely, save numbers and symbols to a text file using "textfile". Let's first look at the saving function. Click the messages from top to bottom:

Now Pd has created a text file called "file1.txt" in the same directory as the patch. It contains:

          hello;
          world!;

"add" creates a symbol or number and follows it with a semicolon. "add2" doesn't create a semicolon.

If you want to read what you've saved, load the file and use "rewind" to go all the way to the beginning. Now every time you hit 'bang', one line (up to the semicolon) will be sent through the left outlet. After the last line, a bang is sent out the right outlet.

You can also write something and read it with an object without ever saving it as a file. You can also use "clear" to delete everything. "set" first deletes everything and then begins a new line. Click from top to bottom:

You can also load a file so that the semicolons don't appear:

"write name.txt cr" also works in the same way.

#### 4.2.1.2 Qlist

A practical expansion to "textfile" is "qlist". This can be used to send chronologically ordered messages with a text file to "receive" objects. The file "orders.txt" has these contents:

          0 tom 55;
          1000 imi -12;
          4000 tom 3;
          2000 imi -2;

At the beginning, "tom" receives the number 55; one second later, "imi" receives -12; four seconds later "tom" receives 3; two seconds later "imi" receives -2. It works the same way with symbols.

Otherwise, "qlist" has the same functions as "textfile": add, add2, rewind, clear.

You can also modify the tempo using "tempo" and a factor:

### 4.2.2 Applications

#### 4.2.2.1 Score for a patch

Provided the sounds have been assembled, you can now write a piece of music as a text file. Let's say you have this patch...

patches/4-2-2-1-score.pd

...and this "score" (patches/p.txt):

          0 p1off 1000;
          0 p1togg 1;
          0 p1amp 1;
          0 amp 0.5;

          3000 p2off 100;
          0 p2togg 1;
          0 p2amp 1;

          2000 p2off 400;

          3000 p1amp 0.2;

          3000 p2amp 0;

          1000 p2off 2100;
          0 p2amp 0.8;

          5000 amp 0;
          0 p1togg 0;
          0 p2togg 0;

You could also write information from sounds:

patches/4-2-2-1-write-score.pd

#### 4.2.2.2 More exercises

Write stochastic algorithms into a text file that uses a "qlist" to play back the patch from 4.2.2.1 at different speeds.

### 4.2.3 Appendix

#### 4.2.3.1 Modifying qlist

The time for qlist are delta values, that is, they always describe the time interval from one event to the next. Sometimes it might be more practical to write text file with absolute time intervals instead. The "remote" object can be used to accomplish this. "remote" (not available in the original version of Pd; it's part of Pd-extended) receives the name of a receive object as a list followed by the value that you want to send there. This saves you from having to use several "sends":

So you can build your own qlist using absolute values:

patches/4-2-3-1-klist.pd

And here's how to change a list of delta values into absolute values:

patches/4-2-3-1-klist-convert1.pd

And conversely:

patches/4-2-3-1-klist-convert2.pd

### 4.2.4 For those especially interested

#### 4.2.4.1 Creating lists externally: Lisp

You can also take "textfile" to use text files that contain previously conducted algorithms. There are special programming languages that can accomplish this. One of these languages is LISP, which is especially well suited to the creation and processing of lists:

http://en.wikipedia.org/wiki/Lisp_(programming_language)

| Up |
Chapter 4. Controlling sound | Home | 4.3 HIDs