Direct importer use
Server-side rendering, headless conversion pipelines, bulk model transforms β anywhere you want the parsed Score without a rendering surface, you skip AlphaTabApi and drive the importer yourself.
When you want a Score, not a rendered surfaceβ
AlphaTabApi is the right entry point when you want alphaTab to render, play, and manage the visual surface. It is not the right entry point when you want the parsed model without any of that:
- A CLI or build script that converts scores from Guitar Pro to alphaTex.
- A backend that ingests uploaded
.gpfiles and pulls out titles, artists, or track counts. - A test harness that constructs the model, mutates it, and inspects the result without a DOM.
- A pipeline that hands the parsed
Scoreto a custom renderer or exporter.
ScoreLoader is the public entry point for these cases. It exposes three static methods that cover every input:
ScoreLoader.loadScoreFromBytes(bytes, settings?)β synchronous, format-detected, throwsUnsupportedFormatErroron failure.ScoreLoader.loadAlphaTex(text, settings?)β synchronous, parses alphaTex directly.ScoreLoader.loadScoreAsync(url, success, error, settings?)β the browser fetch path, callback-based.
The bytes method is what you reach for on Node.js and every non-browser runtime.
The importer classes themselvesβ
alphaTab.importer publicly exports:
ScoreLoaderβ the format-detecting entry point above.ScoreImporterβ the abstract base every format-specific importer extends.AlphaTexImporterβ the alphaTex parser, exposed directly because its API is richer thanScoreLoader.loadAlphaTex(custom error handling, incremental parsing).AlphaTexErrorWithDiagnosticsβ the error type raised on alphaTex parse failures, with line and column info.UnsupportedFormatErrorβ raised byScoreLoaderwhen no importer accepts the bytes.alphaTexβ a nested namespace with the lexer / parser primitives for advanced tooling.
The format-specific importers (Gp7To8Importer, Gp3To5Importer, MusicXmlImporter, CapellaImporter, GpxImporter) are internal β ScoreLoader.loadScoreFromBytes selects and drives them for you. Instantiate a ScoreLoader or an AlphaTexImporter; leave the rest to the loader.
Show it in codeβ
import * as alphaTab from '@coderline/alphatab';
import { readFile } from 'node:fs/promises';
const bytes = new Uint8Array(await readFile('song.gp'));
const score = alphaTab.importer.ScoreLoader.loadScoreFromBytes(bytes);
console.log(`${score.title} β ${score.tracks.length} tracks`);
for (const track of score.tracks) {
console.log(` ${track.name}, ${track.staves.length} staves`);
}
// Round-trip to alphaTex without ever creating an API instance.
const exporter = new alphaTab.exporter.AlphaTexExporter();
const tex = exporter.export(score);
No getAlphaTabContainer() here β this path never touches a rendering surface. Everything is model-in, model-out.
Where to look nextβ
- Score to JSON and back β pair direct-loader use with model serialization.
- Export to alphaTex β the exporter counterpart shown above.
- Programmatic score construction β build a
Scorewithout any importer. - Handling load errors β errors surface as thrown exceptions here, not through the
errorevent. ScoreLoader,ScoreImporter,AlphaTexImporter,AlphaTexErrorWithDiagnostics, andUnsupportedFormatErrorin the reference.Score,Track, andStaffβ the returned model types.