Skip to main content

Export Data Model

since 1.2.0

After alphaTab has loaded a full Score object from any input source, it can also be exported again to one of the supported export formats. Supported export formats:

  • Guitar Pro 7 (alphaTab.exporter.Gp7Exporter) since 1.2.0
  • alphaTex (alphaTab.exporter.AlphaTexExporter) since 1.7.0

To export a Score object the corresponding exporter needs to be created and called. Then the resulting binary array can be used further to trigger a download, send it to a server, save it to a file etc.

Guitar Pro 7 (since 1.2.0)​

const exporter = new alphaTab.exporter.Gp7Exporter();
const data = exporter.export(api.score, api.settings); // will return a Uint8Array

// trigger download
const a = document.createElement('a');
a.download = api.score.title.length > 0 ? api.score.title + '.gp' : 'Untitled.gp';
a.href = URL.createObjectURL(new Blob([data]));
document.body.appendChild(a);
a.click();
document.body.removeChild(a);

alphaTex Exporter (since 1.7.0)​

Starting with 1.7.0 alphaTab can also export the data model to its own music notation language alphaTex. The exporter supports all features which the importer can also handle. If you find something, please open a feature request.

Via the exporter settings settings.exporter the format of the exported code can be adjusted. Especially the comments can be quite useful for alphaTex beginners to learn about the syntax.

While you can use the standard export to export the code into a byte array, you can also use exportToString to get the alphaTex code back as plain string.

const exporter = new alphaTab.exporter.AlphaTexExporter();
const data = exporter.export(api.score, api.settings); // will return a Uint8Array
const texCode = exporter.exportToString(api.score, api.settings); // will return a string

// trigger download
const a = document.createElement('a');
a.download = api.score.title.length > 0 ? api.score.title + '.atex' : 'Untitled.atex';
a.href = URL.createObjectURL(new Blob([data]));
document.body.appendChild(a);
a.click();
document.body.removeChild(a);