Fixes inverted triangle wave by renaming it to itri, making non-inverted tri (#1283)

* add itri / itri2 .. but should tri and itri be swapped??

* swap tri/tri2 with itri/itri2. Add some basic docs for bipolar signals
This commit is contained in:
Alex McLean 2025-02-11 15:34:23 +00:00 committed by GitHub
parent 84581b22aa
commit aabc82bedd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 225 additions and 29 deletions

View File

@ -20,9 +20,6 @@ export const signal = (func) => {
return new Pattern(query);
};
export const isaw = signal((t) => 1 - (t % 1));
export const isaw2 = isaw.toBipolar();
/**
* A sawtooth signal between 0 and 1.
*
@ -36,8 +33,40 @@ export const isaw2 = isaw.toBipolar();
*
*/
export const saw = signal((t) => t % 1);
/**
* A sawtooth signal between -1 and 1 (like `saw`, but bipolar).
*
* @return {Pattern}
*/
export const saw2 = saw.toBipolar();
/**
* A sawtooth signal between 1 and 0 (like `saw`, but flipped).
*
* @return {Pattern}
* @example
* note("<c3 [eb3,g3] g2 [g3,bb3]>*8")
* .clip(isaw.slow(2))
* @example
* n(isaw.range(0,8).segment(8))
* .scale('C major')
*
*/
export const isaw = signal((t) => 1 - (t % 1));
/**
* A sawtooth signal between 1 and -1 (like `saw2`, but flipped).
*
* @return {Pattern}
*/
export const isaw2 = isaw.toBipolar();
/**
* A sine signal between -1 and 1 (like `sine`, but bipolar).
*
* @return {Pattern}
*/
export const sine2 = signal((t) => Math.sin(Math.PI * 2 * t));
/**
@ -61,6 +90,12 @@ export const sine = sine2.fromBipolar();
*
*/
export const cosine = sine._early(Fraction(1).div(4));
/**
* A cosine signal between -1 and 1 (like `cosine`, but bipolar).
*
* @return {Pattern}
*/
export const cosine2 = sine2._early(Fraction(1).div(4));
/**
@ -72,6 +107,12 @@ export const cosine2 = sine2._early(Fraction(1).div(4));
*
*/
export const square = signal((t) => Math.floor((t * 2) % 2));
/**
* A square signal between -1 and 1 (like `square`, but bipolar).
*
* @return {Pattern}
*/
export const square2 = square.toBipolar();
/**
@ -82,9 +123,37 @@ export const square2 = square.toBipolar();
* n(tri.segment(8).range(0,7)).scale("C:minor")
*
*/
export const tri = fastcat(isaw, saw);
export const tri2 = fastcat(isaw2, saw2);
export const tri = fastcat(saw, isaw);
/**
* A triangle signal between -1 and 1 (like `tri`, but bipolar).
*
* @return {Pattern}
*/
export const tri2 = fastcat(saw2, isaw2);
/**
* An inverted triangle signal between 1 and 0 (like `tri`, but flipped).
*
* @return {Pattern}
* @example
* n(itri.segment(8).range(0,7)).scale("C:minor")
*
*/
export const itri = fastcat(isaw, saw);
/**
* An inverted triangle signal between -1 and 1 (like `itri`, but bipolar).
*
* @return {Pattern}
*/
export const itri2 = fastcat(isaw2, saw2);
/**
* A signal representing the cycle time.
*
* @return {Pattern}
*/
export const time = signal(id);
/**

View File

@ -4261,6 +4261,96 @@ exports[`runs examples > example "iresponse" example index 0 1`] = `
]
`;
exports[`runs examples > example "isaw" example index 0 1`] = `
[
"[ 0/1 → 1/8 | note:c3 clip:1 ]",
"[ 1/8 → 1/4 | note:eb3 clip:0.9375 ]",
"[ 1/8 → 1/4 | note:g3 clip:0.9375 ]",
"[ 1/4 → 3/8 | note:g2 clip:0.875 ]",
"[ 3/8 → 1/2 | note:g3 clip:0.8125 ]",
"[ 3/8 → 1/2 | note:bb3 clip:0.8125 ]",
"[ 1/2 → 5/8 | note:c3 clip:0.75 ]",
"[ 5/8 → 3/4 | note:eb3 clip:0.6875 ]",
"[ 5/8 → 3/4 | note:g3 clip:0.6875 ]",
"[ 3/4 → 7/8 | note:g2 clip:0.625 ]",
"[ 7/8 → 1/1 | note:g3 clip:0.5625 ]",
"[ 7/8 → 1/1 | note:bb3 clip:0.5625 ]",
"[ 1/1 → 9/8 | note:c3 clip:0.5 ]",
"[ 9/8 → 5/4 | note:eb3 clip:0.4375 ]",
"[ 9/8 → 5/4 | note:g3 clip:0.4375 ]",
"[ 5/4 → 11/8 | note:g2 clip:0.375 ]",
"[ 11/8 → 3/2 | note:g3 clip:0.3125 ]",
"[ 11/8 → 3/2 | note:bb3 clip:0.3125 ]",
"[ 3/2 → 13/8 | note:c3 clip:0.25 ]",
"[ 13/8 → 7/4 | note:eb3 clip:0.1875 ]",
"[ 13/8 → 7/4 | note:g3 clip:0.1875 ]",
"[ 7/4 → 15/8 | note:g2 clip:0.125 ]",
"[ 15/8 → 2/1 | note:g3 clip:0.0625 ]",
"[ 15/8 → 2/1 | note:bb3 clip:0.0625 ]",
"[ 2/1 → 17/8 | note:c3 clip:1 ]",
"[ 17/8 → 9/4 | note:eb3 clip:0.9375 ]",
"[ 17/8 → 9/4 | note:g3 clip:0.9375 ]",
"[ 9/4 → 19/8 | note:g2 clip:0.875 ]",
"[ 19/8 → 5/2 | note:g3 clip:0.8125 ]",
"[ 19/8 → 5/2 | note:bb3 clip:0.8125 ]",
"[ 5/2 → 21/8 | note:c3 clip:0.75 ]",
"[ 21/8 → 11/4 | note:eb3 clip:0.6875 ]",
"[ 21/8 → 11/4 | note:g3 clip:0.6875 ]",
"[ 11/4 → 23/8 | note:g2 clip:0.625 ]",
"[ 23/8 → 3/1 | note:g3 clip:0.5625 ]",
"[ 23/8 → 3/1 | note:bb3 clip:0.5625 ]",
"[ 3/1 → 25/8 | note:c3 clip:0.5 ]",
"[ 25/8 → 13/4 | note:eb3 clip:0.4375 ]",
"[ 25/8 → 13/4 | note:g3 clip:0.4375 ]",
"[ 13/4 → 27/8 | note:g2 clip:0.375 ]",
"[ 27/8 → 7/2 | note:g3 clip:0.3125 ]",
"[ 27/8 → 7/2 | note:bb3 clip:0.3125 ]",
"[ 7/2 → 29/8 | note:c3 clip:0.25 ]",
"[ 29/8 → 15/4 | note:eb3 clip:0.1875 ]",
"[ 29/8 → 15/4 | note:g3 clip:0.1875 ]",
"[ 15/4 → 31/8 | note:g2 clip:0.125 ]",
"[ 31/8 → 4/1 | note:g3 clip:0.0625 ]",
"[ 31/8 → 4/1 | note:bb3 clip:0.0625 ]",
]
`;
exports[`runs examples > example "isaw" example index 1 1`] = `
[
"[ 0/1 → 1/8 | note:D4 ]",
"[ 1/8 → 1/4 | note:C4 ]",
"[ 1/4 → 3/8 | note:B3 ]",
"[ 3/8 → 1/2 | note:A3 ]",
"[ 1/2 → 5/8 | note:G3 ]",
"[ 5/8 → 3/4 | note:F3 ]",
"[ 3/4 → 7/8 | note:E3 ]",
"[ 7/8 → 1/1 | note:D3 ]",
"[ 1/1 → 9/8 | note:D4 ]",
"[ 9/8 → 5/4 | note:C4 ]",
"[ 5/4 → 11/8 | note:B3 ]",
"[ 11/8 → 3/2 | note:A3 ]",
"[ 3/2 → 13/8 | note:G3 ]",
"[ 13/8 → 7/4 | note:F3 ]",
"[ 7/4 → 15/8 | note:E3 ]",
"[ 15/8 → 2/1 | note:D3 ]",
"[ 2/1 → 17/8 | note:D4 ]",
"[ 17/8 → 9/4 | note:C4 ]",
"[ 9/4 → 19/8 | note:B3 ]",
"[ 19/8 → 5/2 | note:A3 ]",
"[ 5/2 → 21/8 | note:G3 ]",
"[ 21/8 → 11/4 | note:F3 ]",
"[ 11/4 → 23/8 | note:E3 ]",
"[ 23/8 → 3/1 | note:D3 ]",
"[ 3/1 → 25/8 | note:D4 ]",
"[ 25/8 → 13/4 | note:C4 ]",
"[ 13/4 → 27/8 | note:B3 ]",
"[ 27/8 → 7/2 | note:A3 ]",
"[ 7/2 → 29/8 | note:G3 ]",
"[ 29/8 → 15/4 | note:F3 ]",
"[ 15/4 → 31/8 | note:E3 ]",
"[ 31/8 → 4/1 | note:D3 ]",
]
`;
exports[`runs examples > example "iter" example index 0 1`] = `
[
"[ 0/1 → 1/4 | note:A3 ]",
@ -4303,6 +4393,43 @@ exports[`runs examples > example "iterBack" example index 0 1`] = `
]
`;
exports[`runs examples > example "itri" example index 0 1`] = `
[
"[ 0/1 → 1/8 | note:C4 ]",
"[ 1/8 → 1/4 | note:Bb3 ]",
"[ 1/4 → 3/8 | note:G3 ]",
"[ 3/8 → 1/2 | note:Eb3 ]",
"[ 1/2 → 5/8 | note:C3 ]",
"[ 5/8 → 3/4 | note:Eb3 ]",
"[ 3/4 → 7/8 | note:G3 ]",
"[ 7/8 → 1/1 | note:Bb3 ]",
"[ 1/1 → 9/8 | note:C4 ]",
"[ 9/8 → 5/4 | note:Bb3 ]",
"[ 5/4 → 11/8 | note:G3 ]",
"[ 11/8 → 3/2 | note:Eb3 ]",
"[ 3/2 → 13/8 | note:C3 ]",
"[ 13/8 → 7/4 | note:Eb3 ]",
"[ 7/4 → 15/8 | note:G3 ]",
"[ 15/8 → 2/1 | note:Bb3 ]",
"[ 2/1 → 17/8 | note:C4 ]",
"[ 17/8 → 9/4 | note:Bb3 ]",
"[ 9/4 → 19/8 | note:G3 ]",
"[ 19/8 → 5/2 | note:Eb3 ]",
"[ 5/2 → 21/8 | note:C3 ]",
"[ 21/8 → 11/4 | note:Eb3 ]",
"[ 11/4 → 23/8 | note:G3 ]",
"[ 23/8 → 3/1 | note:Bb3 ]",
"[ 3/1 → 25/8 | note:C4 ]",
"[ 25/8 → 13/4 | note:Bb3 ]",
"[ 13/4 → 27/8 | note:G3 ]",
"[ 27/8 → 7/2 | note:Eb3 ]",
"[ 7/2 → 29/8 | note:C3 ]",
"[ 29/8 → 15/4 | note:Eb3 ]",
"[ 15/4 → 31/8 | note:G3 ]",
"[ 31/8 → 4/1 | note:Bb3 ]",
]
`;
exports[`runs examples > example "jux" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd pan:0 ]",
@ -8999,38 +9126,38 @@ exports[`runs examples > example "transpose" example index 1 1`] = `
exports[`runs examples > example "tri" example index 0 1`] = `
[
"[ 0/1 → 1/8 | note:C4 ]",
"[ 1/8 → 1/4 | note:Bb3 ]",
"[ 0/1 → 1/8 | note:C3 ]",
"[ 1/8 → 1/4 | note:Eb3 ]",
"[ 1/4 → 3/8 | note:G3 ]",
"[ 3/8 → 1/2 | note:Eb3 ]",
"[ 1/2 → 5/8 | note:C3 ]",
"[ 5/8 → 3/4 | note:Eb3 ]",
"[ 3/8 → 1/2 | note:Bb3 ]",
"[ 1/2 → 5/8 | note:C4 ]",
"[ 5/8 → 3/4 | note:Bb3 ]",
"[ 3/4 → 7/8 | note:G3 ]",
"[ 7/8 → 1/1 | note:Bb3 ]",
"[ 1/1 → 9/8 | note:C4 ]",
"[ 9/8 → 5/4 | note:Bb3 ]",
"[ 7/8 → 1/1 | note:Eb3 ]",
"[ 1/1 → 9/8 | note:C3 ]",
"[ 9/8 → 5/4 | note:Eb3 ]",
"[ 5/4 → 11/8 | note:G3 ]",
"[ 11/8 → 3/2 | note:Eb3 ]",
"[ 3/2 → 13/8 | note:C3 ]",
"[ 13/8 → 7/4 | note:Eb3 ]",
"[ 11/8 → 3/2 | note:Bb3 ]",
"[ 3/2 → 13/8 | note:C4 ]",
"[ 13/8 → 7/4 | note:Bb3 ]",
"[ 7/4 → 15/8 | note:G3 ]",
"[ 15/8 → 2/1 | note:Bb3 ]",
"[ 2/1 → 17/8 | note:C4 ]",
"[ 17/8 → 9/4 | note:Bb3 ]",
"[ 15/8 → 2/1 | note:Eb3 ]",
"[ 2/1 → 17/8 | note:C3 ]",
"[ 17/8 → 9/4 | note:Eb3 ]",
"[ 9/4 → 19/8 | note:G3 ]",
"[ 19/8 → 5/2 | note:Eb3 ]",
"[ 5/2 → 21/8 | note:C3 ]",
"[ 21/8 → 11/4 | note:Eb3 ]",
"[ 19/8 → 5/2 | note:Bb3 ]",
"[ 5/2 → 21/8 | note:C4 ]",
"[ 21/8 → 11/4 | note:Bb3 ]",
"[ 11/4 → 23/8 | note:G3 ]",
"[ 23/8 → 3/1 | note:Bb3 ]",
"[ 3/1 → 25/8 | note:C4 ]",
"[ 25/8 → 13/4 | note:Bb3 ]",
"[ 23/8 → 3/1 | note:Eb3 ]",
"[ 3/1 → 25/8 | note:C3 ]",
"[ 25/8 → 13/4 | note:Eb3 ]",
"[ 13/4 → 27/8 | note:G3 ]",
"[ 27/8 → 7/2 | note:Eb3 ]",
"[ 7/2 → 29/8 | note:C3 ]",
"[ 29/8 → 15/4 | note:Eb3 ]",
"[ 27/8 → 7/2 | note:Bb3 ]",
"[ 7/2 → 29/8 | note:C4 ]",
"[ 29/8 → 15/4 | note:Bb3 ]",
"[ 15/4 → 31/8 | note:G3 ]",
"[ 31/8 → 4/1 | note:Bb3 ]",
"[ 31/8 → 4/1 | note:Eb3 ]",
]
`;