Per-element colors
Every level of the score model โ score, track, staff, bar, voice, beat, note โ carries a style container. Assign a color to any sub-element and the render reflects it. Use it to highlight a wrong note in a tutor app, tint a specific voice, or theme the whole document.
Where the elements liveโ
Each level exposes its own SubElement enum of individually colorable parts:
ScoreSubElementโ title, subtitle, artist, album, copyright, tempo mark.TrackSubElementโ track name, accolade bracket, string tuning.BarSubElementโ barlines, bar numbers, key and time signature glyphs.VoiceSubElementโ beam, tuplet bracket.BeatSubElementโ stem, flag, chord name, beat text.NoteSubElementโ note head, accidental, tab fret text, fingering, effect glyph.
The full enumeration for each level lives in the model reference.
Show it in codeโ
Coloring is applied post-load, so wire it in a scoreLoaded handler:
import * as alphaTab from '@coderline/alphatab';
const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
core: { file: '/scores/song.gp' },
});
api.scoreLoaded.on((score) => {
score.style = new alphaTab.model.ScoreStyle();
score.style.colors.set(
alphaTab.model.ScoreSubElement.Title,
alphaTab.model.Color.fromJson('#426d9d')
);
for (const track of score.tracks) {
track.style = new alphaTab.model.TrackStyle();
track.style.colors.set(
alphaTab.model.TrackSubElement.StringTuning,
alphaTab.model.Color.fromJson('#e04c4c')
);
}
});
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โ
- Coloring guide โ the deep walkthrough with every sub-element enumerated and worked examples.
Colorand theSubElementenums in the model reference.