Skip to main content

Playing a beat or a note

A score editor lets the user click a chord and hear it. An ear-training drill previews the target note before it asks the student to sing it back. Both of those need the same thing: play one item from the score in isolation, without moving the main transport. That is what playBeat(beat) and playNote(note) do.

Click a beat to hear it. Click one note in a chord to audition that single note.Last auditioned: nothing yet

The audition methodsโ€‹

  • playBeat(beat) โ€” synthesize the notes of one beat and route them through the audio pipeline once. Chords, effects, and per-note articulations render exactly as they would during full playback.
  • playNote(note) โ€” synthesize a single note in isolation. Useful when the reader needs to hear one voice out of a chord, or when the UI reacts to a hover instead of a full-beat selection.

Both methods generate a one-time MIDI file and hand it to the synth. Any current playback is stopped. The main tick position, the cursor, and the playerStateChanged event stay put โ€” the audition is a side-channel, not a seek.

Wiring auditions to clicksโ€‹

The beatMouseDown event fires with the Beat under the pointer whenever the user clicks the score. Pass it straight to playBeat for a click-to-hear editor UX. For per-note hover-to-audition, use noteMouseDown (or its Move variant) and hand the resulting Note to playNote.

Auditioning a beat during active playback is safe: alphaTab pauses the current playback, plays the audition, and leaves the transport in the paused state.

Show it in codeโ€‹

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

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

api.beatMouseDown.on((beat) => {
api.playBeat(beat);
});

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โ€‹