fix: waveform rendering to respect track duration vs project duration
- Calculate trackWidth based on track duration ratio to project duration - Shorter tracks now render proportionally instead of stretching - Longer tracks automatically update project duration - All existing tracks re-render correctly when duration changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -339,14 +339,18 @@ export function Track({
|
||||
} else {
|
||||
totalWidth = width;
|
||||
}
|
||||
const samplesPerPixel = buffer.length / totalWidth;
|
||||
|
||||
// Calculate how much of the canvas width this track's duration occupies
|
||||
const trackDurationRatio = buffer.duration / duration;
|
||||
const trackWidth = width * trackDurationRatio;
|
||||
const samplesPerPixel = buffer.length / trackWidth;
|
||||
|
||||
// Draw waveform
|
||||
ctx.fillStyle = track.color;
|
||||
ctx.strokeStyle = track.color;
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let x = 0; x < trackWidth; x++) {
|
||||
const startSample = Math.floor(x * samplesPerPixel);
|
||||
const endSample = Math.floor((x + 1) * samplesPerPixel);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user