Difference between revisions of "Combining pattern structure"

From TidalCycles userbase
Jump to: navigation, search
(Marked this version for translation)
 
(28 intermediate revisions by 3 users not shown)
Line 1: Line 1:
**This does not describe current behaviour - this is upcoming in version 1.0.0.**
+
<translate>
  
<syntaxhighlight lang = "Haskell">
+
= Combining numerical patterns = <!--T:31-->
d1 $ sound "bd sn"
 
</syntaxhighlight>
 
  
 +
<!--T:2-->
 +
A core feature of Tidal is the ease in which two patterns can be combined.
  
In old Tidal, when combining two patterns, "structure always comes
+
<!--T:27-->
from the left". In the new tidal, you can choose where the structure comes from.
+
For example, these are two patterns being combined by adding together their elements:
  
For example:
+
<!--T:3-->
```
+
<syntaxhighlight lang = "Haskell">
 
"2 3" + "4 5 6"
 
"2 3" + "4 5 6"
```
+
</syntaxhighlight>
 +
 
 +
<!--T:28-->
 +
The result of the above is equivalent to the pattern <syntaxhighlight lang = "Haskell" inline>"6 [7 8] 9"</syntaxhighlight>. But why?
  
These two patterns line up like this:
+
<!--T:4-->
 +
Let's look closer. The two patterns line up over time like this:
  
```
+
<!--T:5-->
|  2  |  3  |
+
<pre>
| 4 | 5 | 6 |
+
  |  2  |  3  |
```
+
+ | 4 | 5 | 6 |
 +
</pre>
  
Now by default, the structure comes from _both sides_, so you end up with _four_
+
<!--T:6-->
events. I've shown the four events below:
+
Unlike in previous versions of Tidal, when you combine two patterns in this way, by default the structure now comes from ''both patterns''. This means you end up with ''four'' events, because the <syntaxhighlight lang="Haskell" inline>5</syntaxhighlight> in the middle lines up both with the <syntaxhighlight lang="Haskell" inline>2</syntaxhighlight> and the <syntaxhighlight lang="Haskell" inline>3</syntaxhighlight>, and gets split in half between them. We can add the resulting pattern to our table:
  
```
+
<!--T:7-->
 +
<pre>
 
   |  2  |  3  |
 
   |  2  |  3  |
 
+ | 4 | 5 | 6 |
 
+ | 4 | 5 | 6 |
 
= | 6 |7|8| 9 |
 
= | 6 |7|8| 9 |
```
+
</pre>
  
You can see that the event with the value of `4` fits in the event
+
<!--T:8-->
with value of `2`, so you get a new event equalling their sum `6`. You
+
You can see that the <syntaxhighlight lang="Haskell" inline>4</syntaxhighlight> fits inside <syntaxhighlight lang="Haskell" inline>2</syntaxhighlight>, so where they intersect, you get a new event equal to their sum <syntaxhighlight lang="Haskell" inline>6</syntaxhighlight>.
can see that the onset and duration is the interection, which in this
 
case is just the onset and duration of the original event with the
 
value `4`.
 
  
Also see that the event with value `5` is cut in half, to create two,
+
<!--T:9-->
shorter events. Half matches with the `2` event and the other half
+
Also see that the event with value <syntaxhighlight lang="Haskell" inline>5</syntaxhighlight> is cut in half, to create two,
matches with the `3` event. Again, the onset and duration of both
+
shorter events. Half matches with the <syntaxhighlight lang="Haskell" inline>2</syntaxhighlight> event and the other half
events comes from the intersections.
+
matches with the <syntaxhighlight lang="Haskell" inline>3</syntaxhighlight> event.
  
The fourth and final event comes from the intersection of `3` and `6`,
+
<!--T:10-->
giving a value of `9`.
+
The fourth and final event comes from the intersection of <syntaxhighlight lang="Haskell" inline>3</syntaxhighlight> and <syntaxhighlight lang="Haskell" inline>6</syntaxhighlight>,
 +
giving a value of <syntaxhighlight lang="Haskell" inline>9</syntaxhighlight>.
  
## Structure from the left
+
== Structure from the left == <!--T:11-->
  
The old behaviour was to take the structure from the left. You can
+
<!--T:12-->
still do this, but in this case using `|+`.  
+
In previous versions of Tidal, the structure always came from the left. You can still do this, but in this case using <syntaxhighlight lang="Haskell" inline>|+</syntaxhighlight>.  
  
 +
<!--T:13-->
 
For example:
 
For example:
  
```
+
<!--T:14-->
 +
<syntaxhighlight lang="Haskell">
 
"2 3" |+ "4 5 6"
 
"2 3" |+ "4 5 6"
```
+
</syntaxhighlight>
 
 
In the above example, you end up with structure from the first, leftmost pattern, like this:
 
  
 +
<!--T:15-->
 +
In the above example, you end up with structure from the first (leftmost) pattern, like this:
  
```
+
<!--T:16-->
 +
<pre>
 
   |  2  |  3  |
 
   |  2  |  3  |
 
|+ | 4 | 5 | 6 |
 
|+ | 4 | 5 | 6 |
 
  = |  6  |  8  |
 
  = |  6  |  8  |
```
+
</pre>
  
You can see the structure comes from the `2` and `3`. `2` lines up
+
<!--T:17-->
with `4`, and the start of `3` is in `5`, so you end up with `2+4=6`
+
You can see the structure comes from the <syntaxhighlight lang="Haskell" inline>2</syntaxhighlight> and <syntaxhighlight lang="Haskell" inline>3</syntaxhighlight>. <syntaxhighlight lang="Haskell" inline>2</syntaxhighlight> lines up
and `3+5=8`.
+
with <syntaxhighlight lang="Haskell" inline>4</syntaxhighlight>, and the start of <syntaxhighlight lang="Haskell" inline>3</syntaxhighlight> is in <syntaxhighlight lang="Haskell" inline>5</syntaxhighlight>, so you end up with <syntaxhighlight lang="Haskell" inline>2+4=6</syntaxhighlight>
 +
and <syntaxhighlight lang="Haskell" inline>3+5=8</syntaxhighlight>. The result is the equivalent of <syntaxhighlight lang="Haskell" inline>"6 8"</syntaxhighlight>
  
## Structure from the right
+
== Structure from the right == <!--T:18-->
  
Likewise, you can take the structure from the right, with `+|`. So `"2
+
<!--T:19-->
3" +| "4 5 6"` looks like:
+
Likewise, you can take the structure from the right, with <syntaxhighlight lang="Haskell" inline>+|</syntaxhighlight>. So <syntaxhighlight lang="Haskell" inline>"2
 +
3" +| "4 5 6"</syntaxhighlight> looks like:
  
```
+
<!--T:20-->
 +
<pre>
 
   |  2  |  3  |
 
   |  2  |  3  |
 
+| | 4 | 5 | 6 |
 
+| | 4 | 5 | 6 |
 
  = | 6 | 7 | 9 |
 
  = | 6 | 7 | 9 |
```
+
</pre>
 +
 
 +
<!--T:29-->
 +
The result is the equivalent of <syntaxhighlight lang="Haskell" inline>"6 7 9"</syntaxhighlight>.
 +
 
 +
== All the operators == <!--T:21-->
  
## All the operators
+
<!--T:30-->
 +
So far, we've just looked at
  
Note that `+` is actually an alias for `|+|`. So `|+` is to take the
+
<!--T:22-->
structure from the left, `+|` from the right, and `|+|` or `+` for
+
Note that <syntaxhighlight lang="Haskell" inline>+</syntaxhighlight> is actually an alias for <syntaxhighlight lang="Haskell" inline>|+|</syntaxhighlight>. So <syntaxhighlight lang="Haskell" inline>|+</syntaxhighlight> is to take the
both. Here are all the basic operators you can use to combine
+
structure from the left, <syntaxhighlight lang="Haskell" inline>+|</syntaxhighlight> from the right, and <syntaxhighlight lang="Haskell" inline>|+|</syntaxhighlight> or <syntaxhighlight lang="Haskell" inline>+</syntaxhighlight> for
structure:
+
both. Here are the basic operators you can use to combine numerical patterns:
  
Function     Both     Left Right  
+
<!--T:23-->
--------    --------- ----- ------
+
{| class="wikitable"
Add         `|+|`/`+` `|+`  `+|`
+
! Function
Multiply     `|*|`/`*` `|*`  `*|`
+
! Both
Subtract    `|-|`/`-` `|-`  `-|`
+
! Left
Divide      `|/|`/`/` `|/`  `/|`
+
! Right  
Modulo       `|%|`    `|%`  `%|`
+
|-
Left values `|<|`    `|<`  `<|`
+
|Add  
Right values `|>|`/`#` `|>`  `>|`
+
| <syntaxhighlight lang="Haskell" inline>|+|</syntaxhighlight> (or <syntaxhighlight lang="Haskell" inline>+</syntaxhighlight>)
 +
| <syntaxhighlight lang="Haskell" inline>|+</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>+|</syntaxhighlight>
 +
|-
 +
|Subtract
 +
| <syntaxhighlight lang="Haskell" inline>|-|</syntaxhighlight> (or <syntaxhighlight lang="Haskell" inline>-</syntaxhighlight>)
 +
| <syntaxhighlight lang="Haskell" inline>|-</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>-|</syntaxhighlight>
 +
|-
 +
|Multiply
 +
| <syntaxhighlight lang="Haskell" inline>|*|</syntaxhighlight> (or <syntaxhighlight lang="Haskell" inline>*</syntaxhighlight>)
 +
| <syntaxhighlight lang="Haskell" inline>|*</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>*|</syntaxhighlight>
 +
|-
 +
|Divide
 +
| <syntaxhighlight lang="Haskell" inline>|/|</syntaxhighlight> (or <syntaxhighlight lang="Haskell" inline>/</syntaxhighlight>)
 +
| <syntaxhighlight lang="Haskell" inline>|/</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>/|</syntaxhighlight>
 +
|-
 +
|Modulo
 +
| <syntaxhighlight lang="Haskell" inline>|%|</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>|%</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>%|</syntaxhighlight>
 +
|-
 +
|Left values
 +
| <syntaxhighlight lang="Haskell" inline>|<|</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>|<</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline><|</syntaxhighlight>
 +
|-
 +
|Right values
 +
| <syntaxhighlight lang="Haskell" inline>|>|</syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>|></syntaxhighlight>
 +
| <syntaxhighlight lang="Haskell" inline>>|</syntaxhighlight>
 +
|}
  
 +
<!--T:24-->
 
The last two are interesting, they let you only take values from one
 
The last two are interesting, they let you only take values from one
 
side. So for example you could take structure from the left, but
 
side. So for example you could take structure from the left, but
values from the right with `|>`, for example:
+
values from the right with <syntaxhighlight lang="Haskell" inline>|></syntaxhighlight>, for example:
  
```
+
<!--T:25-->
 +
<pre>
 
   |  2  |  3  |
 
   |  2  |  3  |
 
|> | 4 | 5 | 6 |
 
|> | 4 | 5 | 6 |
  = |  2 9 |
+
  = |  4 5 |
```
+
</pre>
 +
 
 +
<!--T:26-->
 +
This is very similar to how <syntaxhighlight lang="Haskell" inline>|+|</syntaxhighlight> used to work in the versions of tidal prior to 1.0.0 - it took structure from the left, but values from the right. In fact, <syntaxhighlight lang="Haskell" inline>#</syntaxhighlight> is an alias for <syntaxhighlight lang="Haskell" inline>|></syntaxhighlight>, mirroring the behaviour in previous versions of tidal.
 +
</translate>
 +
 
 +
= Combining control patterns =
 +
 
 +
A control pattern (formerly known as a 'param pattern'), is a pattern that's been given a control name. For example the number pattern <syntaxhighlight lang="Haskell" inline>"1 2 3"</syntaxhighlight> can be turned into a control pattern like this <syntaxhighlight>speed "1 2 3"</syntaxhighlight>.
 +
 
 +
Control patterns can be combined together in the same way as numerical patterns. For example:
 +
 
 +
<syntaxhighlight lang="Haskell">
 +
d1 $ sound "drum" |+| n "1 2 3"
 +
</syntaxhighlight>
 +
 
 +
Nothing actually gets added together in the above, they're just combined into the equivalent of <syntaxhighlight lang="Haskell" inline>d1 $ sound "drum:1 drum:2 drum:3"</syntaxhighlight>. However if you specify the same numerical control more than once, then their values _will_ be combined. For example:
 +
 
 +
<syntaxhighlight lang="Haskell">
 +
d1 $ sound "drum" |+| n "2 3" |+| n "4 5 6"
 +
</syntaxhighlight>
 +
 
 +
The above will be equivalent to:
 +
 
 +
<syntaxhighlight lang="Haskell">
 +
d1 $ sound "drum" |+| n "6 [7 8] 9"
 +
</syntaxhighlight>
  
This is actually how `#` works in the current tidal.
+
[[Category:Tidal-1+]]
 +
[[Category:Reference]]

Latest revision as of 22:00, 14 December 2019

Combining numerical patterns

A core feature of Tidal is the ease in which two patterns can be combined.

For example, these are two patterns being combined by adding together their elements:

"2 3" + "4 5 6"

The result of the above is equivalent to the pattern "6 [7 8] 9". But why?

Let's look closer. The two patterns line up over time like this:

  |  2  |  3  |
+ | 4 | 5 | 6 |

Unlike in previous versions of Tidal, when you combine two patterns in this way, by default the structure now comes from both patterns. This means you end up with four events, because the 5 in the middle lines up both with the 2 and the 3, and gets split in half between them. We can add the resulting pattern to our table:

  |  2  |  3  |
+ | 4 | 5 | 6 |
= | 6 |7|8| 9 |

You can see that the 4 fits inside 2, so where they intersect, you get a new event equal to their sum 6.

Also see that the event with value 5 is cut in half, to create two, shorter events. Half matches with the 2 event and the other half matches with the 3 event.

The fourth and final event comes from the intersection of 3 and 6, giving a value of 9.

Structure from the left

In previous versions of Tidal, the structure always came from the left. You can still do this, but in this case using |+.

For example:

"2 3" |+ "4 5 6"

In the above example, you end up with structure from the first (leftmost) pattern, like this:

   |  2  |  3  |
|+ | 4 | 5 | 6 |
 = |  6  |  8  |

You can see the structure comes from the 2 and 3. 2 lines up with 4, and the start of 3 is in 5, so you end up with 2+4=6 and 3+5=8. The result is the equivalent of "6 8"

Structure from the right

Likewise, you can take the structure from the right, with +|. So "2 3" +| "4 5 6" looks like:

   |  2  |  3  |
+| | 4 | 5 | 6 |
 = | 6 | 7 | 9 |

The result is the equivalent of "6 7 9".

All the operators

So far, we've just looked at

Note that + is actually an alias for |+|. So |+ is to take the structure from the left, +| from the right, and |+| or + for both. Here are the basic operators you can use to combine numerical patterns:

Function Both Left Right
Add |+| (or +) |+ +|
Subtract |-| (or -) |- -|
Multiply |*| (or *) |* *|
Divide |/| (or /) |/ /|
Modulo |%| |% %|
Left values |<| |< <|
Right values |>| |> >|

The last two are interesting, they let you only take values from one side. So for example you could take structure from the left, but values from the right with |>, for example:

   |  2  |  3  |
|> | 4 | 5 | 6 |
 = |  4  |  5  |

This is very similar to how |+| used to work in the versions of tidal prior to 1.0.0 - it took structure from the left, but values from the right. In fact, # is an alias for |>, mirroring the behaviour in previous versions of tidal.

Combining control patterns

A control pattern (formerly known as a 'param pattern'), is a pattern that's been given a control name. For example the number pattern "1 2 3" can be turned into a control pattern like this

speed "1 2 3"

.

Control patterns can be combined together in the same way as numerical patterns. For example:

d1 $ sound "drum" |+| n "1 2 3"

Nothing actually gets added together in the above, they're just combined into the equivalent of d1 $ sound "drum:1 drum:2 drum:3". However if you specify the same numerical control more than once, then their values _will_ be combined. For example:

d1 $ sound "drum" |+| n "2 3" |+| n "4 5 6"

The above will be equivalent to:

d1 $ sound "drum" |+| n "6 [7 8] 9"