fix op loop expansion, rendering

This commit is contained in:
Stewart Allen 2026-01-02 22:49:36 -05:00
commit 0bdadd7294
2 changed files with 25 additions and 48 deletions

View file

@ -95,7 +95,8 @@ function updateIndex() {
if (op.absolute) {
index = op.degrees
} else {
index += op.degrees;
let numloop = op._numloop ?? 1;
index += (op.degrees * numloop);
}
}
}
@ -288,6 +289,8 @@ export function opRender() {
let bind = {};
let scale = api.view.unit_scale();
let notime = false;
let inloop = 0;
let numloop;
oplist.forEach((rec, i) => {
let title = '';
let clock = rec.type === '|';
@ -300,22 +303,12 @@ export function opRender() {
label = `loop ${rec.repeat || 2}x`;
clazz.push('loop');
title = ` title="loop: repeat next ${rec.count || 1} operation(s) ${rec.repeat || 2} time(s)"`;
}
// Check if this operation is within N operations after a loop
let inLoopRange = false;
for (let j = i - 1; j >= 0; j--) {
if (oplist[j].type === 'loop') {
let loopCount = oplist[j].count || 1;
let distanceFromLoop = i - j;
if (distanceFromLoop <= loopCount && distanceFromLoop > 0) {
inLoopRange = true;
break;
}
}
}
if (inLoopRange) {
inloop = rec.count;
numloop = rec.repeat;
} else if (inloop && !clock) {
clazz.push('in-loop');
rec._numloop = numloop;
inloop--;
}
let notable = rec.note ? rec.note.split(' ').filter(v => v.charAt(0) === '#') : undefined;
@ -375,7 +368,8 @@ export function opRender() {
let popped = false;
let poprec = env.popOp[rec.type];
if (type === 'index' && indexing && !rec.disabled) {
index = rec.absolute ? rec.degrees : index + rec.degrees;
let numloop = rec._numloop ?? 1;
index = rec.absolute ? rec.degrees : index + (rec.degrees * numloop);
}
el.rec = rec;
el.unpop = () => {

View file

@ -309,6 +309,7 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
opList.push(new OPS.xray(state, { type: "xray" }));
}
// find index ops
let activeOps = proc.ops.filter(op => !op.disabled);
if (isIndexed) {
@ -326,45 +327,27 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
// LOOP EXPANSION - duplicate next N operations M times
let expandedOps = [];
let i = 0;
while (i < activeOps.length) {
for (let i=0; i<activeOps.length; i++) {
let op = activeOps[i];
if (op.type === 'loop') {
let repeatCount = op.repeat || 2; // M times
let opCount = op.count || 1; // N operations
// Validate we have enough operations
if (i + opCount >= activeOps.length) {
return error(`Loop operation requires ${opCount} following operation(s), but only ${activeOps.length - i - 1} available`);
let { count, repeat } = op;
let remain = activeOps.slice(i+1).filter(op => op.type !== '|');
if (remain < count) {
return error(`Loop operation requires ${count} following operation(s), but only ${remain.length - i - 1} available`);
}
// Extract next N operations
let loopOps = activeOps.slice(i + 1, i + 1 + opCount);
// Check for nested loops
for (let loopOp of loopOps) {
if (loopOp.type === 'loop') {
return error("Nested loops are not supported");
for (let r=1; r<repeat; r++)
for (let c=0; c<count; c++) {
let dup = remain[c];
if (dup.type === 'loop') {
return error("Nested loops are not supported");
}
expandedOps.push(dup);
}
}
// Duplicate operations M times
for (let r = 0; r < repeatCount; r++) {
for (let loopOp of loopOps) {
let clonedOp = Object.clone(loopOp);
expandedOps.push(clonedOp);
}
}
// Skip the loop operation itself and the N operations
i += 1 + opCount;
} else if (op.type === '|') {
break; // Clock operation
break;
} else {
expandedOps.push(op);
i++;
}
}