start packaging
This commit is contained in:
parent
a19d789145
commit
6f60a3a1d5
98 changed files with 11162 additions and 11122 deletions
29
packages/core/euclid.mjs
Normal file
29
packages/core/euclid.mjs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { Pattern, timeCat } from './strudel.mjs';
|
||||
import bjork from 'bjork';
|
||||
import { rotate } from '../../packages/core/util.mjs';
|
||||
import Fraction from './fraction.mjs';
|
||||
|
||||
const euclid = (pulses, steps, rotation = 0) => {
|
||||
const b = bjork(steps, pulses);
|
||||
if (rotation) {
|
||||
return rotate(b, -rotation);
|
||||
}
|
||||
return b;
|
||||
};
|
||||
|
||||
Pattern.prototype.euclid = function (pulses, steps, rotation = 0) {
|
||||
return this.struct(euclid(pulses, steps, rotation));
|
||||
};
|
||||
|
||||
Pattern.prototype.euclidLegato = function (pulses, steps, rotation = 0) {
|
||||
const bin_pat = euclid(pulses, steps, rotation);
|
||||
const firstOne = bin_pat.indexOf(1);
|
||||
const gapless = rotate(bin_pat, firstOne)
|
||||
.join('')
|
||||
.split('1')
|
||||
.slice(1)
|
||||
.map((s) => [s.length + 1, true]);
|
||||
return this.struct(timeCat(...gapless)).late(Fraction(firstOne).div(steps));
|
||||
};
|
||||
|
||||
export default euclid;
|
||||
Loading…
Add table
Add a link
Reference in a new issue