Exercise 8.1 - State and Counters 1 2  

Variables allow us to set and store temporary or changeable information that we can draw upon in code. One particularly useful application is in keeping track of the current state of the music, which can be used to create progressions and iterative processes - varying repeats to add form and structure to a passage of music. In combination with the repeating pattern, they can be used like an SB0/SBx repeat (accessed with .repeat - see Tutorial 4), but which allow us to see, set, and control the current value. Such "counters" are even evident in traditional music to keep track of a musician's place in a piece (i.e. bar or measure number).

Define a variable to use as a bar counter:

The pattern shown is based on repetitions of the first bar (16 rows). Every time the cell is played, the number increases, allowing us to use this variable as a counter to track time or progress through the music.

  Other formulas in the pattern will read the counter and make decisions on what to do, so as to evolve the music over time, as explored in part 2.

Exercise 8.2 - Counters and Progressions 1 2  

In this exercise, you will use the @Bar counter to selectively unmute channels in the rest of our pattern, which contain the building blocks for a piece of electronic dance music: drums, bass, lead, pad, etc. The piece is created from a single bar that simply repeats - but, as the counter increases, new layers will be added or removed from the mix to provide a musical progression.

Add rules to unmute the initial channels:

The remaining channels use a combination of handwritten music and formulas to provide new layers that build and vary the piece. Some contain formulas that reference @Bar themselves, or use their own variables (e.g. @Note) or arrays (e.g. @Notes) - some may even mute other channels, based on conditions or variables (overriding your earlier code!).

Define rules to unmute the remaining channels: