Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 64cc8ca

Browse files
authored
Merge pull request #1038 from tidalcycles/swing
add swing + swingBy
2 parents f427b56 + 97d292a commit 64cc8ca

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

packages/core/pattern.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,24 @@ export const segment = register('segment', function (rate, pat) {
19761976
return pat.struct(pure(true)._fast(rate)).setTactus(rate);
19771977
});
19781978

1979+
/**
1980+
* The function `swingBy x n` breaks each cycle into `n` slices, and then delays events in the second half of each slice by the amount `x`, which is relative to the size of the (half) slice. So if `x` is 0 it does nothing, `0.5` delays for half the note duration, and 1 will wrap around to doing nothing again. The end result is a shuffle or swing-like rhythm
1981+
* @param {number} subdivision
1982+
* @param {number} offset
1983+
* @example
1984+
* s("hh*8").swingBy(1/3, 4)
1985+
*/
1986+
export const swingBy = register('swingBy', (swing, n, pat) => pat.inside(n, late(seq(0, swing / 2))));
1987+
1988+
/**
1989+
* Shorthand for swingBy with 1/3:
1990+
* @param {number} subdivision
1991+
* @example
1992+
* s("hh*8").swing(4)
1993+
* // s("hh*8").swingBy(1/3, 4)
1994+
*/
1995+
export const swing = register('swing', (n, pat) => pat.swingBy(1 / 3, n));
1996+
19791997
/**
19801998
* Swaps 1s and 0s in a binary pattern.
19811999
* @name invert

test/__snapshots__/examples.test.mjs.snap

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7298,6 +7298,112 @@ exports[`runs examples > example "sustain" example index 0 1`] = `
72987298
]
72997299
`;
73007300

7301+
exports[`runs examples > example "swing" example index 0 1`] = `
7302+
[
7303+
"[ 0/1 → 1/8 | s:hh ]",
7304+
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
7305+
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
7306+
"[ 1/4 → 3/8 | s:hh ]",
7307+
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
7308+
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
7309+
"[ 1/2 → 5/8 | s:hh ]",
7310+
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
7311+
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
7312+
"[ 3/4 → 7/8 | s:hh ]",
7313+
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
7314+
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
7315+
"[ 1/1 → 9/8 | s:hh ]",
7316+
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
7317+
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
7318+
"[ 5/4 → 11/8 | s:hh ]",
7319+
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
7320+
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
7321+
"[ 3/2 → 13/8 | s:hh ]",
7322+
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
7323+
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
7324+
"[ 7/4 → 15/8 | s:hh ]",
7325+
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
7326+
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
7327+
"[ 2/1 → 17/8 | s:hh ]",
7328+
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
7329+
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
7330+
"[ 9/4 → 19/8 | s:hh ]",
7331+
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
7332+
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
7333+
"[ 5/2 → 21/8 | s:hh ]",
7334+
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
7335+
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
7336+
"[ 11/4 → 23/8 | s:hh ]",
7337+
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
7338+
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
7339+
"[ 3/1 → 25/8 | s:hh ]",
7340+
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
7341+
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
7342+
"[ 13/4 → 27/8 | s:hh ]",
7343+
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
7344+
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
7345+
"[ 7/2 → 29/8 | s:hh ]",
7346+
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
7347+
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
7348+
"[ 15/4 → 31/8 | s:hh ]",
7349+
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
7350+
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
7351+
]
7352+
`;
7353+
7354+
exports[`runs examples > example "swingBy" example index 0 1`] = `
7355+
[
7356+
"[ 0/1 → 1/8 | s:hh ]",
7357+
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
7358+
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
7359+
"[ 1/4 → 3/8 | s:hh ]",
7360+
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
7361+
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
7362+
"[ 1/2 → 5/8 | s:hh ]",
7363+
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
7364+
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
7365+
"[ 3/4 → 7/8 | s:hh ]",
7366+
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
7367+
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
7368+
"[ 1/1 → 9/8 | s:hh ]",
7369+
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
7370+
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
7371+
"[ 5/4 → 11/8 | s:hh ]",
7372+
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
7373+
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
7374+
"[ 3/2 → 13/8 | s:hh ]",
7375+
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
7376+
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
7377+
"[ 7/4 → 15/8 | s:hh ]",
7378+
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
7379+
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
7380+
"[ 2/1 → 17/8 | s:hh ]",
7381+
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
7382+
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
7383+
"[ 9/4 → 19/8 | s:hh ]",
7384+
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
7385+
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
7386+
"[ 5/2 → 21/8 | s:hh ]",
7387+
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
7388+
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
7389+
"[ 11/4 → 23/8 | s:hh ]",
7390+
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
7391+
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
7392+
"[ 3/1 → 25/8 | s:hh ]",
7393+
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
7394+
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
7395+
"[ 13/4 → 27/8 | s:hh ]",
7396+
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
7397+
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
7398+
"[ 7/2 → 29/8 | s:hh ]",
7399+
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
7400+
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
7401+
"[ 15/4 → 31/8 | s:hh ]",
7402+
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
7403+
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
7404+
]
7405+
`;
7406+
73017407
exports[`runs examples > example "timecat" example index 0 1`] = `
73027408
[
73037409
"[ 0/1 → 3/4 | note:e3 ]",

website/src/pages/learn/time-modifiers.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,12 @@ Some of these have equivalent operators in the Mini Notation:
106106

107107
<JsDoc client:idle name="ribbon" h={0} />
108108

109+
## swingBy
110+
111+
<JsDoc client:idle name="swingBy" h={0} />
112+
113+
## swing
114+
115+
<JsDoc client:idle name="swing" h={0} />
116+
109117
Apart from modifying time, there are ways to [Control Parameters](/functions/value-modifiers/).

0 commit comments

Comments
 (0)