Skip to main content

Multi-bar rests

Collapse runs of empty (or rest-only) bars into a single multi-bar rest glyph with a count above it โ€” the traditional big-band notation for a horn section that sits out for eight bars, or a sight-reader's cue for how long an educational score's empty stretch runs. Ensemble parts get shorter, sight-readers get a clearer count, and the layout algorithm has fewer bars to squeeze onto each row.

Score-wide vs cherry-pickingโ€‹

Two fields on score.stylesheet control the feature:

  • multiTrackMultiBarRest โ€” a boolean. When true and multiple tracks are rendered together, subsequent bars that are empty on every rendered track collapse into one multi-bar rest.
  • perTrackMultiBarRest โ€” a Set<number> of track indexes. Add a track's index to opt it in. When it is null (default), the score-wide rules apply as-is; when it holds indexes, only those tracks participate in multi-bar-rest collapsing.

The two work together. In a full-band render, multiTrackMultiBarRest = true collapses empty regions across the band. If you're rendering a subset โ€” a solo transcription of the bass line โ€” populate perTrackMultiBarRest with the track index to get the same behavior on a single-track render.

If your goal is not to compress rests but to hide a track when it has nothing to say for a while, two adjacent flags do that instead:

  • hideEmptyStaves โ€” hides staves whose entire content in a system is empty.
  • hideEmptyStavesInFirstSystem โ€” extends the same behavior to the first system, which normally stays visible so the reader sees every part at least once.

These are independent from the multi-bar-rest flags and can be combined.

Show it in codeโ€‹

import * as alphaTab from '@coderline/alphatab';

const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
});

api.scoreLoaded.on((score) => {
// Enable it band-wide:
score.stylesheet.multiTrackMultiBarRest = true;

// Or cherry-pick which tracks participate:
score.stylesheet.perTrackMultiBarRest = new Set(
score.tracks.filter((t) => t.name.includes('Bass')).map((t) => t.index)
);

api.render();
});

getAlphaTabContainer() is a placeholder for the platform-specific step of obtaining the render target โ€” a <div> on Web, an AlphaTab control on .NET, or an AlphaTabView on Android. Every other line runs unchanged on all three runtimes.

Where to look nextโ€‹