Rendering a slice
display.startBar and display.barCount render a window of consecutive bars out of a larger score. Reach for them to build a practice UI that paginates a long piece four bars at a time, to isolate a phrase for a tutorial page, or to generate embedded thumbnails of specific passages โ all without loading a different file each time.
The two knobsโ
display.startBarโ the first bar to render, one-based.1is the beginning of the score (the default),5starts the render at bar 5.display.barCountโ how many consecutive bars to include.-1(the default) renders every bar fromstartBarto the end.
The rest of the score model is still loaded and available for playback, event hooks, and bounds lookup โ only the visible render is trimmed. Playback still traverses the full score unless you also constrain player.playbackRange.
To change the visible slice at runtime, mutate api.settings.display.startBar and api.settings.display.barCount, then call api.updateSettings() followed by api.render().
Show it in codeโ
import * as alphaTab from '@coderline/alphatab';
const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
display: {
startBar: 4,
barCount: 8,
},
});
// Later โ page forward eight bars
document.getElementById('next-page').addEventListener('click', () => {
api.settings.display.startBar += 8;
api.updateSettings();
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โ
- Page layout โ the wrapping mode this slice usually renders in.
display.startBaranddisplay.barCountreference entries.updateSettingsโ apply setting mutations at runtime.