Score following in PDRP

This page describes the score following facility used by all the patches in the PD Repertory Project (PDRP) It uses the Risset study patch as an example.


Score following
Example: Risset, Sketches


back to table of contents All the patches in the series use the same overall control strategy. Each patch has one or more "qlists" which are sequences of messages. The messages can control audio or MIDI processes or even the sequencing itself.

Some, but not all, of the pieces use score following to synchronize the sequences automatically with a live instrument. The score follower can use MIDI input (from a piano, for example) or can use the acoustic input from a solo instrument, which must be analyzed using a pitch tracker.

The pitch tracker, the score follower, and the sequencer control the rest of the patch as shown here:

In this picture, the sequencer is controlled by the score follower. The score follower can take input either from incoming MIDI or the pitch tracker, or just from the computer mouse. The audio processing portion of the patch is controlled by the sequencer and can make use of incoming audio and MIDI as well.

For each section of the piece, a "score" and a "qlist" are needed, to be used by the score follower and sequencer, respectively.

Each of the Pd patches has an area on the main window for controlling the score follower, sequencer, and master audio settings:

Sequencer controls

In the upper left are the sequencer controls, which start, stop and "step" the sequence:

Here there is only one section, number 100. (In patches that implement real pieces there will also be one or more "real" sections numbered starting at one.)( Section number 100 provides a simple example of how to use the patch. When you develop your own examples you'll load them into section 100. Each section consists of some number of "steps" or "events". The steps are numbered starting from 0 (which is the beginning of the section.) When you click on the "step" button you'll see the step number increase by one. Most qlists will have an event at the end that resets everything to zero so you can see when you're done. The number boxes show you the current section and "event". Also, if you are using score following, the "note" number box shows you the numerical index of the most recent note matched by the score follower.


The meters in the main control panel are useful primarily for debugging score following. (Some patches will have other VU meters in more easily readable format to show you the separate input and output levels by channel.) The meters look as shown here:

At the top is a toggle switch to turn them on and off. When you're not looking at them it's best to leave them off (in some situations graphics compete with the rest of the patch for CPU time.) The input level is in dB with 100 meaning "full blast and clipping". Only the channel one input is shown; this is used for pitch tracking.

The "tuning" meter should give the pitch of the acoustic input, or zero if none. The "rest" meter (actually a toggle) is on when the instrument is not playing (i.e. the amplitude drops below 50 db and stays there for 1/2 second; you can customize these values if you want.) You can use "rest" as a pitch for the score follower if you want an event to be set off at some point after the instrument stops playing.

Score following controls Three toggle switches control whether the pitch tracker is turned on, and whether to follow teh score based on the pitch tracker or incoming MIDI:

These can be controlled from the qlist; by default the pitch tracker is on, but score following is taken from MIDI input. The qlist messages to change this are:

    pitch-track-on 1;       -- to start pitch tracking
    pitch-track-on 0;       -- to stop it
    follow-pitch 1;         -- follow pitch tracking
    follow-pitch 0;         -- don't

    follow-midi 1;          -- follow MIDI
    follow-midi 0;          -- don't

Master input and output gain

Master input and output gain are in dB with 100 set to unity. The controls appear as shown:

You can drag the values up and down; values over 100 are permitted, but be warned that each 10 dB gives a large boost in amplitude... don't put the output control to 200 because you don't hear anything; when you get sound output working you might be blown out of the room.

The "mute" control toggles the master output gain to and from zero.

Score following

back to table of contents

You can click on the "pd score" box in the sequencer control panel to open a window with controls for editing the score and qlist for "section 100" (This section is for demos and is not part of any of the repertory pieces:)

Clicking the score-editor gives you:

For either qlists or scores you can:
Open a file and read it into Pd's qlist or score follower;
Save the current qlist or following score to a file;
Print the current qlist or following score to the "terminal";
Edit the current qlist or following score in a text window.

The "edit" feature only works under Linux, not Windows. When you select "edit" Pd will save your qlist or following score to a file and call a text editor on it. (NOTE: Pd will freeze until you exit the text editor!) When you're done editing the new score or qlist is automatically read into Pd. You can then "save" it to your own file.

In case you forget to save the score or qlist to a file before exiting Pd, Pd always puts a copy of the most recently edited score and/or qlist in the files, "last-score.txt" and "last-qlists.txt" which you can then rename using Unix commands -- and should rename before another editing session overwrites the file.

For the following score, not the qlist, you also have controls to record a score from the piano. When you hit "stop" Pd starts an editor with the score as if you had hit "edit".

The following score will need to be annotated with markers to show where the "events" are. This is shown by example in the next section.

Example: Risset's Sketches

back to table of contents

The simplest patch in the series is one to do MIDI transpositions and reflections, inspired by Risset's second sketch. You can start the patch and try out the transformations, play the "section 100" sketch provided, or make your own sketch.

Scores and qlists can be broken into sections. In the score provided for the Risset example, the section is numbered 100. Section 100 contains a following score as follows:

1000 48

1000 55

1000 60 1

1000 60 2
0 64
0 67

1000 48

1000 55

1000 60 3

1000 60 4
0 63
0 67

1000 48

1000 55

1000 60 5

1000 60 6
0 64
0 67

The score has one line per note; each line has two or three numbers. The first number is a duration in milliseconds, the second is a MIDI pitch, and the third, if present, is an event number. The score above starts with a C, G, and C each one second apart; the second C is event 1. Then there is a C major chord which is event 2. (Actually the first note of the chord is marked with the event.) The same thing is repeated three times with minor variations; the events are numbered one through six. (Event numbers should be sequential, but they don't have to be consecutive as long as the qlist agrees.)

Here is the corresponding qlist:

0 0 # --------------- STARTUP  ----------------- ;
# nothing to do here... ;
# (comments start with "#" and end with a semicolon like this:) ;

0 1 # --------------- EVENT 1 ------------------- ;
# after 1/10 sec, turn on reflection at 63.5;
100 reflect-on 1;
reflect-point 63.5;
reflect-delay 500;

0 2 # --------------- EVENT 2 ------------------- ;
# after 1.5 sec, turn it off again;
1500 reflect-on 0;

0 3 # --------------- EVENT 3 ------------------- ;
# on again;
100 reflect-on 1;

0 4 # --------------- EVENT 4 ------------------- ;
# off again;
1500 reflect-on 0;

0 5 # --------------- EVENT 5 ------------------- ;
# now a transposition down 7 semitones;
100 transpose-on 1;
transpose-interval -7;
transpose-delay 500;

0 6 # --------------- EVENT 6 ------------------- ;
# after 2 sec, turn it off;
2000 transpose-on 0;
# ... and set section number to zero to show that we're done;
section-number 0;

There are six events, not counting "startup." (Startup would be the appropriate place to set up transformations that should be in effect before the piano part starts.) Each event starts with a line like:

0 1 # --------------- EVENT 1 ------------------- ;

... in which the "0 1" means, "time delay 0, event 1". The "1" must be replaced with the current event number. The remainder of the line, starting from "#", is a comment. Comments, and all other messages, must end in semicolons; it's easy to forget them and if you do the succeeding message will simply appear as more stuff at the end of the previous one (which will usually be ignored and you will wonder why nothing happened.) Forgotten semicolons are by far the most common errors in qlists.

The first event, then, after another comment, gets on to the three lines:

100 reflect-on 1;
reflect-point 63.5;
reflect-delay 500;

There are three messages, the first one with a delay of 100 milliseconds, and the others having no delay and so happening immediately after the first. Each message starts with the name of sone control (such as "reflect-on") and sends it a message (such as "1"). You may have as many such messags as you like, and as many time intervals as you like between them. The event is finished only when another EVENT message (one starting with two numbers) is encountered.