Fit a song both ways and zoom its time in further (#362)

Fit in the Song tab only set the time, from the very left edge, and
kept the height the tracks had. The time also stopped zooming at the
bound of the Pattern tab, too soon to lay a take down closely.

- fitSong in songView.ts frames the song with 9 % of the lanes free on
  every side. The tracks share out the height in between, held to
  28 to 320 px. A song opened without a kept view fits the same way.
- The time zooms in to 8 px a tick, eight times the bound of the
  Pattern tab. zoomTime takes the bound as a parameter, so the Pattern
  tab keeps its own.

Tests:
- Unit song-edit: 15 green (1 new), the counter-check without the
  margin is red.
- e2e 65: ALL PASSED, 56 checks (1 new). The new check presses Fit
  after the tracks are added and finds room around bar and tracks.
  Adding a track presses Fit first now: a new song opens with its one
  track 320 px tall, so the track added below it lay off the edge.
- Gate: 272 files, 4213 tests green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-09 07:33:47 +02:00
1 parent 5cb7ef7bed
commit d0b76ec355
5 files changed
+78 -15

No files matched your search

+21
View File
@@ -17,6 +17,8 @@ import {
} from '../../src/editor/song/songEdit';
import {
clampTracks,
FIT_MARGIN,
fitSong,
HEAD_BOXES,
headPartAt,
itemAt,
@@ -28,11 +30,13 @@ import {
peakOver,
SLIDERS_MIN_HEIGHT,
sliderValue,
SONG_MAX_PX_PER_TICK,
type SongView,
TRACK_HEIGHT,
trackAtY,
zoomTracks,
} from '../../src/editor/song/songView';
import { MAX_PX_PER_TICK, tickToX, zoomTime } from '../../src/editor/music/timeView';
const BAR = 1920;
const TRACKS = ['t1', 't2', 't3'];
@@ -222,6 +226,23 @@ describe('where things are in the Song tab (#334)', () => {
});
});
it('fits the song across and its tracks down with room around, and zooms in further than a pattern', () => {
// 4 bars and 4 tracks in 1000 x 500: 90 pixels free left and right, 45 above and below.
const fitted = fitSong(4 * BAR, 4, 1000, 500);
expect(fitted.panX).toBeCloseTo(1000 * FIT_MARGIN);
expect(fitted.panY).toBeCloseTo(500 * FIT_MARGIN);
expect(tickToX(fitted, 4 * BAR)).toBeCloseTo(1000 * (1 - FIT_MARGIN));
expect(fitted.panY + 4 * fitted.trackHeight).toBeCloseTo(500 * (1 - FIT_MARGIN));
// A track keeps the heights it may have, however many or few there are.
expect(fitSong(BAR, 1, 1000, 2000).trackHeight).toBe(MAX_TRACK_HEIGHT);
expect(fitSong(BAR, 60, 1000, 500).trackHeight).toBe(MIN_TRACK_HEIGHT);
// The wheel goes past where a pattern stops, up to the song's own bound.
const deep = zoomTime({ panX: 0, pxPerTick: 1 }, 100, 0, SONG_MAX_PX_PER_TICK);
expect(SONG_MAX_PX_PER_TICK).toBeGreaterThan(MAX_PX_PER_TICK);
expect(deep.pxPerTick).toBe(SONG_MAX_PX_PER_TICK);
expect(fitSong(1, 1, 1000, 500).pxPerTick).toBe(SONG_MAX_PX_PER_TICK);
});
it('marks where an item starts over inside it, from as far in as it starts', () => {
expect(loopSeams({ tick: BAR, length: 3 * BAR }, BAR, 0)).toEqual([2 * BAR, 3 * BAR]);
expect(loopSeams({ tick: BAR, length: 2 * BAR }, BAR, 480)).toEqual([2 * BAR - 480, 3 * BAR - 480]);