mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
drawLine test
This commit is contained in:
parent
766cccf335
commit
2bbd306b94
@ -1,12 +1,15 @@
|
||||
import { gcd } from './fraction.mjs';
|
||||
|
||||
function drawLine(pat) {
|
||||
// TODO: make it work for stacked patterns + support silence
|
||||
|
||||
function drawLine(pat, chars = 60) {
|
||||
let s = '';
|
||||
let c = 0;
|
||||
while (s.length < 60) {
|
||||
while (s.length < chars) {
|
||||
const haps = pat.queryArc(c, c + 1);
|
||||
const durations = haps.map((hap) => hap.duration);
|
||||
const totalSlots = gcd(...durations).inverse();
|
||||
s += '|';
|
||||
haps.forEach((hap) => {
|
||||
const duration = hap.whole.end.sub(hap.whole.begin);
|
||||
const slots = totalSlots.mul(duration);
|
||||
@ -15,7 +18,6 @@ function drawLine(pat) {
|
||||
.map((_, i) => (!i ? hap.value : '-'))
|
||||
.join('');
|
||||
});
|
||||
s += '|';
|
||||
++c;
|
||||
}
|
||||
return s;
|
||||
|
||||
11
packages/core/test/drawLine.test.mjs
Normal file
11
packages/core/test/drawLine.test.mjs
Normal file
@ -0,0 +1,11 @@
|
||||
import { fastcat } from '../pattern.mjs';
|
||||
import { strict as assert } from 'assert';
|
||||
import drawLine from '../drawLine.mjs';
|
||||
|
||||
describe('drawLine', () => {
|
||||
it('should work', () => {
|
||||
assert.equal(drawLine(fastcat(0, [1, 2]), 10), '|0-12|0-12');
|
||||
assert.equal(drawLine(fastcat(0, [1, 2, 3]), 10), '|0--123|0--123');
|
||||
assert.equal(drawLine(fastcat(0, 1, [2, 3]), 10), '|0-1-23|0-1-23');
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user