drawLine test

This commit is contained in:
Felix Roos 2022-04-23 23:47:52 +02:00
parent 766cccf335
commit 2bbd306b94
2 changed files with 16 additions and 3 deletions

View file

@ -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;