Skip to content

Commit 42d2b6c

Browse files
committed
Fixes for the sequencer
1 parent 7b5f8f3 commit 42d2b6c

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

app/app-controller-browser.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,15 @@ class EnhancedPatternApp {
445445
</div>
446446
<div class="analysis-box-content">
447447
<div class="cog-distance-value">
448-
Distance: ${analysis.cogAnalysis?.distance?.toFixed(4) || 'N/A'}
448+
Distance: ${analysis.cogAnalysis?.normalizedMagnitude?.toFixed(4) || analysis.cogAnalysis?.distance?.toFixed(4) || 'N/A'}
449449
</div>
450450
<div class="cog-angle-value">
451-
Angle: ${analysis.cogAnalysis?.angle?.toFixed(1) || 'N/A'}°
451+
Angle: ${analysis.cogAnalysis?.angle?.toFixed(1) ||
452+
(analysis.cogAnalysis?.coordinates ?
453+
Math.atan2(analysis.cogAnalysis.coordinates.y, analysis.cogAnalysis.coordinates.x) * (180 / Math.PI) : 0).toFixed(1)}°
452454
</div>
453455
<div class="cog-description">
454-
${analysis.cogAnalysis?.distance < 0.1 ? '🎯 Geometrically Centered' : 'Pattern analysis'}
456+
${(analysis.cogAnalysis?.normalizedMagnitude || analysis.cogAnalysis?.distance || 1) < 0.1 ? '🎯 Geometrically Centered' : 'Off-center pattern'}
455457
</div>
456458
</div>
457459
</div>

app/sequencer-visual.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class SequencerVisualEngine {
130130
);
131131

132132
console.log(`🎨 Canvas sized: ${size}x${size}px`);
133+
134+
// Trigger re-render now that canvas is properly sized
135+
if (size > 0) {
136+
setTimeout(() => this.render(), 50);
137+
}
133138
}
134139

135140
/**
@@ -183,15 +188,28 @@ class SequencerVisualEngine {
183188
if (typeof CenterOfGravityCalculator !== 'undefined') {
184189
try {
185190
const cogResult = CenterOfGravityCalculator.calculateCenterOfGravity(this.pattern.steps);
186-
this.cogData = {
187-
distance: cogResult.distance,
188-
angle: cogResult.angle,
189-
x: cogResult.x,
190-
y: cogResult.y,
191-
isCalculated: true
192-
};
191+
// CoG calculation successful
193192

194-
console.log(`🎨 CoG calculated: distance=${cogResult.distance.toFixed(3)}, angle=${cogResult.angle.toFixed(2)}°`);
193+
if (cogResult && typeof cogResult.magnitude === 'number') {
194+
// Convert the result format to what we expect
195+
const distance = cogResult.normalizedMagnitude || cogResult.magnitude;
196+
const x = cogResult.coordinates?.x || cogResult.x || 0;
197+
const y = cogResult.coordinates?.y || cogResult.y || 0;
198+
const angle = Math.atan2(y, x) * (180 / Math.PI);
199+
200+
this.cogData = {
201+
distance: distance,
202+
angle: angle,
203+
x: x,
204+
y: y,
205+
isCalculated: true
206+
};
207+
208+
console.log(`🎨 CoG calculated: distance=${distance.toFixed(4)}, angle=${angle.toFixed(1)}°`);
209+
} else {
210+
console.warn('⚠️ Invalid CoG result:', cogResult);
211+
this.cogData.isCalculated = false;
212+
}
195213
} catch (error) {
196214
console.warn('⚠️ CoG calculation failed:', error);
197215
this.cogData.isCalculated = false;
@@ -285,9 +303,20 @@ class SequencerVisualEngine {
285303
return;
286304
}
287305

288-
const startTime = performance.now();
306+
// Skip rendering if canvas isn't properly sized yet
307+
if (this.config.canvasSize <= 0) {
308+
return;
309+
}
289310

290-
console.log(`🎨 Rendering pattern: ${this.pattern.stepCount} steps, canvas: ${this.config.canvasSize}x${this.config.canvasSize}`);
311+
// If canvas element isn't sized yet, try to size it now
312+
if (this.canvas.width <= 0) {
313+
this.setupResponsiveCanvas();
314+
if (this.canvas.width <= 0) {
315+
return;
316+
}
317+
}
318+
319+
const startTime = performance.now();
291320

292321
// Clear canvas
293322
this.ctx.clearRect(0, 0, this.config.canvasSize, this.config.canvasSize);
@@ -464,7 +493,7 @@ class SequencerVisualEngine {
464493
const stepSize = this.config.stepElementActualSize;
465494
const fontSize = stepSize * 0.4;
466495

467-
console.log(`🎨 Drawing ${this.pattern.stepCount} steps:`, this.pattern.steps.slice(0, 8));
496+
// Draw step elements around the circle
468497

469498
for (let i = 0; i < this.pattern.stepCount; i++) {
470499
const angle = (i / this.pattern.stepCount) * Math.PI * 2 - Math.PI / 2;

0 commit comments

Comments
 (0)