mirror of
https://codeberg.org/uzu/strudel
synced 2026-08-12 16:41:26 -04:00
Make legacy the default
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, bench } from 'vitest';
|
||||
|
||||
import { calculateSteps, rand, useOldRandom } from '../index.mjs';
|
||||
import { calculateSteps, rand, useRNG } from '../index.mjs';
|
||||
|
||||
const testingResolution = 128;
|
||||
|
||||
@@ -11,13 +11,13 @@ describe('old random', () => {
|
||||
bench(
|
||||
'+tactus',
|
||||
() => {
|
||||
useOldRandom();
|
||||
useRNG('legacy');
|
||||
_generateRandomPattern();
|
||||
},
|
||||
{
|
||||
time: 1000,
|
||||
teardown() {
|
||||
useOldRandom(false);
|
||||
useRNG('legacy');
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -26,13 +26,13 @@ describe('old random', () => {
|
||||
bench(
|
||||
'-tactus',
|
||||
() => {
|
||||
useOldRandom();
|
||||
useRNG('precise');
|
||||
_generateRandomPattern();
|
||||
},
|
||||
{
|
||||
time: 1000,
|
||||
teardown() {
|
||||
useOldRandom(false);
|
||||
useRNG('legacy');
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -231,7 +231,8 @@ const timeToRands = (t, n, seed = 0) => {
|
||||
return out;
|
||||
};
|
||||
|
||||
// Deprecated: Old random signals. Configuration `useOldRandom` may be used for legacy songs
|
||||
// Old random signals. Currently the default, but can also be chosen via
|
||||
// `useRNG('legacy')`
|
||||
|
||||
// stretch 300 cycles over the range of [0,2**29 == 536870912) then apply the xorshift algorithm
|
||||
const __xorwise = (x) => {
|
||||
@@ -257,23 +258,25 @@ const __timeToRands = (t, n) => __timeToRandsPrime(__timeToIntSeed(t), n);
|
||||
|
||||
// End old random
|
||||
|
||||
let useOldRandomBool = false;
|
||||
let RNG_MODE = 'legacy';
|
||||
export const getRandsAtTime = (t, n = 1, seed = 0) => {
|
||||
return useOldRandomBool ? __timeToRands(t + seed, n) : timeToRands(t, n, seed);
|
||||
return RNG_MODE === 'legacy' ? __timeToRands(t + seed, n) : timeToRands(t, n, seed);
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether to use the old random number generator or not. Can be used to support legacy projects
|
||||
* Sets which random number generator to use. Historically Strudel would
|
||||
* use `useRNG('legacy')`, which remains the default. To use a new more statistically
|
||||
* precise RNG, try `useRNG('precise')`.
|
||||
*
|
||||
* @name useOldRandom
|
||||
* @param {boolean} b - Whether to use old RNG
|
||||
* @name useRNG
|
||||
* @param {string} mod - Mode. One of 'legacy', 'precise'
|
||||
* @example
|
||||
* useOldRandom(true)
|
||||
* useRNG('legacy')
|
||||
* // Repeats every 300 cycles
|
||||
* $: n(irand(50)).seg(16).scale("C:minor").ribbon(88, 32)
|
||||
* $: n(irand(50)).seg(16).scale("C:minor").ribbon(388, 32)
|
||||
*/
|
||||
export const useOldRandom = (b = true) => (useOldRandomBool = b);
|
||||
export const useRNG = (mode = 'legacy') => (RNG_MODE = mode);
|
||||
|
||||
/**
|
||||
* A discrete pattern of numbers from 0 to n-1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { afterEach } from 'vitest';
|
||||
import { useOldRandom } from './packages/core/signal.mjs';
|
||||
import { useRNG } from './packages/core/signal.mjs';
|
||||
|
||||
afterEach(() => {
|
||||
// Avoid bleed between tests
|
||||
useOldRandom(false);
|
||||
useRNG('legacy');
|
||||
});
|
||||
|
||||
+10
-10
@@ -393,7 +393,7 @@ samples({
|
||||
bass: { d2: 'https://cdn.freesound.org/previews/608/608286_13074022-lq.mp3' }
|
||||
})
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
// bells
|
||||
@@ -432,7 +432,7 @@ export const festivalOfFingers3 = `// "Festival of fingers 3"
|
||||
// @by Felix Roos
|
||||
|
||||
setcps(1)
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
n("[-7*3],0,2,6,[8 7]")
|
||||
.echoWith(
|
||||
@@ -457,7 +457,7 @@ export const meltingsubmarine = `// "Melting submarine"
|
||||
// @by Felix Roos
|
||||
|
||||
samples('github:tidalcycles/dirt-samples')
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
s("bd:5,[~ <sd:1!3 sd:1(3,4,3)>],hh27(3,4,1)") // drums
|
||||
@@ -608,7 +608,7 @@ export const belldub = `// "Belldub"
|
||||
samples({ bell: {b4:'https://cdn.freesound.org/previews/339/339809_5121236-lq.mp3'}})
|
||||
// "Hand Bells, B, Single.wav" by InspectorJ (www.jshaw.co.uk) of Freesound.org
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
// bass
|
||||
@@ -646,7 +646,7 @@ export const dinofunk = `// "Dinofunk"
|
||||
// @by Felix Roos
|
||||
|
||||
setcps(1)
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
samples({bass:'https://cdn.freesound.org/previews/614/614637_2434927-hq.mp3',
|
||||
dino:{b4:'https://cdn.freesound.org/previews/316/316403_5123851-hq.mp3'}})
|
||||
@@ -675,7 +675,7 @@ export const sampleDemo = `// "Sample demo"
|
||||
// @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
// @by Felix Roos
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
// percussion
|
||||
@@ -695,7 +695,7 @@ export const holyflute = `// "Holy flute"
|
||||
// @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
// @by Felix Roos
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
"c3 eb3(3,8) c4/2 g3*2"
|
||||
.superimpose(
|
||||
@@ -712,7 +712,7 @@ export const flatrave = `// "Flatrave"
|
||||
// @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
// @by Felix Roos
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
s("bd*2,~ [cp,sd]").bank('RolandTR909'),
|
||||
@@ -742,7 +742,7 @@ export const amensister = `// "Amensister"
|
||||
|
||||
samples('github:tidalcycles/dirt-samples')
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
stack(
|
||||
// amen
|
||||
@@ -851,7 +851,7 @@ export const arpoon = `// "Arpoon"
|
||||
// @license CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
// @by Felix Roos
|
||||
|
||||
useOldRandom(true)
|
||||
useRNG('legacy')
|
||||
|
||||
samples('github:tidalcycles/dirt-samples')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user