# Signal Music, Beat and Rhythm
Frank Zappa had a [five-step process](http://pierroule.com/ZappaRealBook/TheRFZBook.htm) to become a composer:
> [!quote]
> [1] Declare your intention to create a "composition."
>
> [2] Start a piece at some time.
>
> [3] Cause something to happen over a period of time (it doesn't matter what happens in your "time hole" — we have critics to tell us whether it's any good or not, so we won't worry about that part).
>
> [4] End the piece at some time (or keep it going, telling the audience it is a "work in progress").
>
> [5] Get a part-time job so you can continue to do stuff like this.
>
> — From "The Real Frank Zappa Book" by Frank Zappa
Music reveals itself through time, so it shouldn't be a surprise that three of the steps have to do with time. This article is all about how to know when things have started, when things have stopped, and how to have things happen over a period of time in procedural music.
![[abstract-patch-2.png]]
## Keeping Time in Signal Music with a Signal Clock
When creating procedural music, we need a way to keep track of time, and play notes when appropriate. For example, we may want to have a bass drum play every quarter note. Or perhaps we want to play a melody, and we need to know when to trigger each note.
Consider a device, which shows a decimal number on a screen. This number increases by 1.0 every second continuously. If you put the device down and picked it back up again, after 3.5 seconds you would see its number increase by 3.5.
If instead the device counted up to 60.0 before flipping back to 0.0, we would have something that behaves like just the second hand of a clock.
Finally, if we had a sort of metronome that went from 0.0 to 1.0 every beat—this would be an example of a ramp wave. Ramp waves can be used to sweep through a wavetable, play back samples or video, or control an instrument. In general, **a ramp wave is a percentage representing a duration of some musical event**. An entire patch can be controlled using little more than ramp waves.
In Max, there many objects are designed to generate or modify ramp waves. A common object is `[phasor~]`.
Normally the frequency of `[phasor~]` (how long it takes to go from 0.0 to 1.0) is specified in hertz. However, you can specify in terms of note values (`4n` is a quarter note, `8n` is an eighth note, and `16n` is a sixteenth note, for example).
In addition, by passing the `@lock 1` argument, it will lock the ramp wave to the global transport, allowing you to sync it to other programs or hardware.
> [!example]
> ![[image-2.png]]
> Two ways to trigger an event every 16 beats in Max, using signals.
## Knowing When the Song Has Started or Stopped
Max has a built-in global transport. You can use `[phasor~ 4n @lock 1]` to create a ramp wave that follows the tempo of the global transport. You can use the `[transport]` object to know when the transport has started or stopped, among other information.
> [!example]
> ![[image-17.png]]
> One way to know if the global transport is started or stopped, as well as the current beat position.
If you double-click a `[transport]` object, or choose GlobalTransport from the Extras menu, you can view the global transport's tempo, current position, and other info.
> [!example]
> ![[image-18.png]]
> The global transport window is one way to change tempo, rewind transport, etc.
Another option for following timing is using Ableton Link. First, install the [Ableton link package](https://cycling74.com/feature/abletonlink). Then, instead of using `[phasor 4n @lock 1]` (for beats) or `[phasor 1.0.0 @lock 1]` (for measures), you can use `[link.phasor~]` which emits a measure ramp out of the left outlet, and a beat ramp out of the right outlet. In general, it's best to depend on using the measure ramp or the beat ramp to schedule your musical events to start, instead of depending on a Link session to know when the performance has started or stopped.
> [!example]
> ![[image-20.png]]
> Ableton Link is a very convenient way to sync instruments across multiple computers.
## Working with Ramps
Ramps represent the duration of some musical event. A ramp at 0.0 means the event hasn't started yet. A ramp at 0.5 means that the event is 50% of the way through. A ramp at 1.0 means the event is complete.
We usually start with a ramp wave representing a beat or a measure. We can perform operations on ramp waves to make them longer or shorter, and use them in all sorts of ways.
> [!example]
> ![[image-24.png]]
> Using `[phasor~]`, we can create repeating, synced ramps. Using `[ramp~]`, we can create unsynced ramp waves.
Addition and multiplication with real numbers can be done on ramp waves. Just be sure to wrap the value in the range of 0.0 and 1.0. This can be done using the `[%~ 1.]` object. Multiplication can be used to divide a ramp into smaller ramps. Addition can be used to slide a ramp over, so it can start halfway through its normal starting point, for example.
> [!example]
> ![[image-23.png]]
> Multiplication and addition on ramps.
Some other useful things to do with ramps: Make a ramp last some multiple longer than normal. Divide it into smaller ramps. Selectively play ramps, shuffle ramps, or delay the start and end by some percentage.
> [!example]
> ![[image-25.png]]
> Common ramp operations.
> [!example]
> ![[image-73.png]]
> From left-to-right: Gate-sequencing with ramps in two different ways. A Euclidean rhythm generator. A "Bernoulli Gate" generator (a gate that is open some percentage of the time)
One useful thing we can do with ramps is turn them into envelopes. This can be done using a combination of `[trapezoid~ 0.01 0.01]` or similar, along with `[twist~ @curve -0.75 @shapemode 0]` or similar.
> [!example]
> ![[image-26.png]]
> Shaping a ramp into an envelope.
There are other things that can be done with ramps as well, such as creating LFOs, playing samples, etc.
## Example: A Procedural Rhythm Section
If we create a ramp wave that goes from 0.0-1.0 every quarter note, it is easy to use that ramp to control the playback of a bass drum sample, or using something like the [[Instrument I, A Wavefolding Synth]] patch to synthesize a bass drum.
The next element we want is a snare drum. If we have a ramp wave that goes from 0.0-1.0 every half note, we can use `[subdiv~ 2 @prob 0 1]` to get a ramp wave that plays every other quarter note. We can then use that ramp to drive a [[Instrument II, Snare Synth]] patch.
Finally, we can use a quarter-note ramp wave and `[subdiv~ 4]` it to get sixteenth-note ramps. We can use these waves to generate repeating phrases that slowly change over time with the [[Instrument III, Percussion Generator]] patch.
> [!example]
> ![[image-16.png]]
> A bass drum patch, a snare drum patch, and a percussion patch playing, synced.
* [[Instrument I, A Wavefolding Synth]]
* [[Instrument II, Noise Synth]]
* [[Instrument III, Percussion Generator]]
Here's what they sound like together:
> [!example]
> ![[example-1.mp4]]
> A performance of the three instruments. ([[example-1.mp4|Click here to view, if it's not displaying]])