diff --git a/components/tracks/Track.tsx b/components/tracks/Track.tsx index 4075b13..77011d6 100644 --- a/components/tracks/Track.tsx +++ b/components/tracks/Track.tsx @@ -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);