Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/alphatab/src/generated/model/BarSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SustainPedalMarker } from "@coderline/alphatab/model/Bar";
import { BarLineStyle } from "@coderline/alphatab/model/Bar";
import { KeySignature } from "@coderline/alphatab/model/KeySignature";
import { KeySignatureType } from "@coderline/alphatab/model/KeySignatureType";
import { BarNumberDisplay } from "@coderline/alphatab/model/RenderStylesheet";
import { BarStyle } from "@coderline/alphatab/model/Bar";
/**
* @internal
Expand Down Expand Up @@ -44,6 +45,7 @@ export class BarSerializer {
o.set("barlineright", obj.barLineRight as number);
o.set("keysignature", obj.keySignature as number);
o.set("keysignaturetype", obj.keySignatureType as number);
o.set("barnumberdisplay", obj.barNumberDisplay as number | undefined);
if (obj.style) {
o.set("style", BarStyleSerializer.toJson(obj.style));
}
Expand Down Expand Up @@ -97,6 +99,9 @@ export class BarSerializer {
case "keysignaturetype":
obj.keySignatureType = JsonHelper.parseEnum<KeySignatureType>(v, KeySignatureType)!;
return true;
case "barnumberdisplay":
obj.barNumberDisplay = JsonHelper.parseEnum<BarNumberDisplay>(v, BarNumberDisplay);
return true;
case "style":
if (v) {
obj.style = new BarStyle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BracketExtendMode } from "@coderline/alphatab/model/RenderStylesheet";
import { TrackNamePolicy } from "@coderline/alphatab/model/RenderStylesheet";
import { TrackNameMode } from "@coderline/alphatab/model/RenderStylesheet";
import { TrackNameOrientation } from "@coderline/alphatab/model/RenderStylesheet";
import { BarNumberDisplay } from "@coderline/alphatab/model/RenderStylesheet";
/**
* @internal
*/
Expand Down Expand Up @@ -62,6 +63,7 @@ export class RenderStylesheetSerializer {
o.set("hideemptystaves", obj.hideEmptyStaves);
o.set("hideemptystavesinfirstsystem", obj.hideEmptyStavesInFirstSystem);
o.set("showsinglestaffbrackets", obj.showSingleStaffBrackets);
o.set("barnumberdisplay", obj.barNumberDisplay as number);
return o;
}
public static setProperty(obj: RenderStylesheet, property: string, v: unknown): boolean {
Expand Down Expand Up @@ -132,6 +134,9 @@ export class RenderStylesheetSerializer {
case "showsinglestaffbrackets":
obj.showSingleStaffBrackets = v! as boolean;
return true;
case "barnumberdisplay":
obj.barNumberDisplay = JsonHelper.parseEnum<BarNumberDisplay>(v, BarNumberDisplay)!;
return true;
}
return false;
}
Expand Down
27 changes: 27 additions & 0 deletions packages/alphatab/src/importer/BinaryStylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BendPoint } from '@coderline/alphatab/model/BendPoint';
import { Bounds } from '@coderline/alphatab/rendering/utils/Bounds';
import { Color } from '@coderline/alphatab/model/Color';
import {
BarNumberDisplay,
type BracketExtendMode,
TrackNameMode,
TrackNameOrientation,
Expand Down Expand Up @@ -347,6 +348,20 @@ export class BinaryStylesheet {
ModelUtils.getOrCreateHeaderFooterStyle(score, ScoreSubElement.CopyrightSecondLine).isVisible =
value as boolean;
break;

case 'System/barIndexDrawType':
switch (value as number) {
case 0:
score.stylesheet.barNumberDisplay = BarNumberDisplay.AllBars;
break;
case 1:
score.stylesheet.barNumberDisplay = BarNumberDisplay.FirstOfSystem;
break;
case 2:
score.stylesheet.barNumberDisplay = BarNumberDisplay.Hide;
break;
}
break;
}
}
}
Expand Down Expand Up @@ -569,6 +584,18 @@ export class BinaryStylesheet {
}
}

switch (score.stylesheet.barNumberDisplay) {
case BarNumberDisplay.AllBars:
binaryStylesheet.addValue('System/barIndexDrawType', 0, DataType.Integer);
break;
case BarNumberDisplay.FirstOfSystem:
binaryStylesheet.addValue('System/barIndexDrawType', 1, DataType.Integer);
break;
case BarNumberDisplay.Hide:
binaryStylesheet.addValue('System/barIndexDrawType', 2, DataType.Integer);
break;
}

const writer = ByteBuffer.withCapacity(128);
binaryStylesheet.writeTo(writer);
return writer.toArray();
Expand Down
80 changes: 68 additions & 12 deletions packages/alphatab/src/importer/MusicXmlImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { NoteOrnament } from '@coderline/alphatab/model/NoteOrnament';
import { Ottavia } from '@coderline/alphatab/model/Ottavia';
import { PercussionMapper } from '@coderline/alphatab/model/PercussionMapper';
import { PickStroke } from '@coderline/alphatab/model/PickStroke';
import { BarNumberDisplay } from '@coderline/alphatab/model/RenderStylesheet';
import { Score } from '@coderline/alphatab/model/Score';
import { Section } from '@coderline/alphatab/model/Section';
import { SimileMark } from '@coderline/alphatab/model/SimileMark';
Expand Down Expand Up @@ -198,6 +199,9 @@ export class MusicXmlImporter extends ScoreImporter {
private _indexToTrackInfo: Map<number, TrackInfo> = new Map<number, TrackInfo>();
private _staffToContext: Map<Staff, StaffContext> = new Map<Staff, StaffContext>();

private _currentBarNumberDisplayPart?: BarNumberDisplay;
private _currentBarNumberDisplayBar?: BarNumberDisplay;

private _divisionsPerQuarterNote: number = 1;
private _currentDynamics = DynamicValue.F;

Expand Down Expand Up @@ -868,23 +872,34 @@ export class MusicXmlImporter extends ScoreImporter {
break;
}
}

this._currentBarNumberDisplayPart = undefined;
}

private _parsePartwiseMeasure(element: XmlNode, track: Track, index: number) {
const masterBar = this._getOrCreateMasterBar(element, index);
this._parsePartMeasure(element, masterBar, track);
const implicit = element.attributes.get('implicit') === 'yes';
this._parsePartMeasure(element, masterBar, track, implicit, true);
this._currentBarNumberDisplayBar = undefined;
}

private _parseTimewiseMeasure(element: XmlNode, index: number) {
const masterBar = this._getOrCreateMasterBar(element, index);
const implicit = element.attributes.get('implicit') === 'yes';

for (const c of element.childElements()) {
switch (c.localName) {
case 'part':
this._parseTimewisePart(c, masterBar);
this._parseTimewisePart(c, masterBar, implicit);
this._currentBarNumberDisplayPart = undefined;
break;
case 'print':
this._parsePrint(c, masterBar, undefined, true);
break;
}
}

this._currentBarNumberDisplayBar = undefined;
}

private _getOrCreateMasterBar(element: XmlNode, index: number) {
Expand All @@ -906,14 +921,14 @@ export class MusicXmlImporter extends ScoreImporter {
return masterBar;
}

private _parseTimewisePart(element: XmlNode, masterBar: MasterBar) {
private _parseTimewisePart(element: XmlNode, masterBar: MasterBar, implicit: boolean) {
const id = element.attributes.get('id');
if (!id || !this._idToTrackInfo.has(id)) {
return;
}

const track = this._idToTrackInfo.get(id)!.track;
this._parsePartMeasure(element, masterBar, track);
this._parsePartMeasure(element, masterBar, track, implicit, false);
}

// current measure state
Expand All @@ -929,7 +944,13 @@ export class MusicXmlImporter extends ScoreImporter {
*/
private _lastBeat: Beat | null = null;

private _parsePartMeasure(element: XmlNode, masterBar: MasterBar, track: Track) {
private _parsePartMeasure(
element: XmlNode,
masterBar: MasterBar,
track: Track,
implicit: boolean,
isPartwise: boolean
) {
this._musicalPosition = 0;
this._lastBeat = null;

Expand Down Expand Up @@ -959,7 +980,7 @@ export class MusicXmlImporter extends ScoreImporter {
break;
// case 'figured-bass': Not supported
case 'print':
this._parsePrint(c, masterBar, track);
this._parsePrint(c, masterBar, track, true);
break;
case 'sound':
this._parseSound(c, masterBar, track);
Expand All @@ -983,17 +1004,52 @@ export class MusicXmlImporter extends ScoreImporter {

// initial empty staff and voice (if no other elements created something already)
const staff = this._getOrCreateStaff(track, 0);
this._getOrCreateBar(staff, masterBar);
const bar = this._getOrCreateBar(staff, masterBar);

if (implicit) {
bar.barNumberDisplay = BarNumberDisplay.Hide;
} else if (isPartwise) {
bar.barNumberDisplay = this._currentBarNumberDisplayBar ?? this._currentBarNumberDisplayPart;
} else {
bar.barNumberDisplay = this._currentBarNumberDisplayPart ?? this._currentBarNumberDisplayBar;
}

// clear measure attribute
this._keyAllStaves = null;
}

private _parsePrint(element: XmlNode, masterBar: MasterBar, track: Track) {
if (element.getAttribute('new-system', 'no') === 'yes') {
track.addLineBreaks(masterBar.index);
} else if (element.getAttribute('new-page', 'no') === 'yes') {
track.addLineBreaks(masterBar.index);
private _parsePrint(element: XmlNode, masterBar: MasterBar, track: Track | undefined, isMeasurePrint: boolean) {
if (track !== undefined) {
if (element.getAttribute('new-system', 'no') === 'yes') {
track.addLineBreaks(masterBar.index);
} else if (element.getAttribute('new-page', 'no') === 'yes') {
track.addLineBreaks(masterBar.index);
}
}

let newDisplay: BarNumberDisplay | undefined = undefined;
for (const c of element.childElements()) {
switch (c.localName) {
case 'measure-numbering':
switch (c.innerText) {
case 'none':
newDisplay = BarNumberDisplay.Hide;
break;
case 'measure':
newDisplay = BarNumberDisplay.AllBars;
break;
case 'system':
newDisplay = BarNumberDisplay.FirstOfSystem;
break;
}
break;
}
}

if (isMeasurePrint) {
this._currentBarNumberDisplayBar = newDisplay;
} else {
this._currentBarNumberDisplayPart = newDisplay;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { NoteAccidentalMode } from '@coderline/alphatab/model/NoteAccidenta
import type { Ottavia } from '@coderline/alphatab/model/Ottavia';
import type { Rasgueado } from '@coderline/alphatab/model/Rasgueado';
import type {
BarNumberDisplay,
BracketExtendMode,
TrackNameMode,
TrackNameOrientation,
Expand Down Expand Up @@ -405,6 +406,14 @@ export class AlphaTex1EnumMappings {
public static readonly tremoloPickingStyleReversed = AlphaTex1EnumMappings._reverse(
AlphaTex1EnumMappings.tremoloPickingStyle
);
public static readonly barNumberDisplay = new Map<string, BarNumberDisplay>([
['allbars', 0],
['firstofsystem', 1],
['hide', 2]
]);
public static readonly barNumberDisplayReversed = AlphaTex1EnumMappings._reverse(
AlphaTex1EnumMappings.barNumberDisplay
);
public static readonly keySignaturesMinorReversed = new Map<KeySignature, string>([
[-7, 'abminor'],
[-6, 'ebminor'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export class AlphaTex1LanguageDefinitions {
['chorddiagramsinscore', [[[[10], 1, ['true', 'false']]]]],
['hideemptystaves', null],
['hideemptystavesinfirstsystem', null],
['showsinglestaffbrackets', null]
['showsinglestaffbrackets', null],
['defaultbarnumberdisplay', [[[[10, 17], 0, ['allbars', 'firstofsystem', 'hide']]]]]
]);
public static readonly staffMetaDataSignatures = AlphaTex1LanguageDefinitions._signatures([
['tuning', [[[[10, 17], 0, ['piano', 'none', 'voice']]], [[[10, 17], 5]]]],
Expand Down Expand Up @@ -478,7 +479,8 @@ export class AlphaTex1LanguageDefinitions {
['sph', [[[[16], 2]]]],
['spu', [[[[16], 2]]]],
['db', null],
['voicemode', [[[[10, 17], 0, ['staffwise', 'barwise']]]]]
['voicemode', [[[[10, 17], 0, ['staffwise', 'barwise']]]]],
['barnumberdisplay', [[[[10, 17], 0, ['allbars', 'firstofsystem', 'hide']]]]]
]);
public static readonly metaDataProperties = AlphaTex1LanguageDefinitions._metaProps([
[
Expand Down Expand Up @@ -536,6 +538,7 @@ export class AlphaTex1LanguageDefinitions {
['hideemptystaves', null],
['hideemptystavesinfirstsystem', null],
['showsinglestaffbrackets', null],
['defaultbarnumberdisplay', null],
[
'tuning',
[
Expand Down Expand Up @@ -592,7 +595,8 @@ export class AlphaTex1LanguageDefinitions {
['sph', null],
['spu', null],
['db', null],
['voicemode', null]
['voicemode', null],
['barnumberdisplay', null]
]);
public static readonly metaDataSignatures = [
AlphaTex1LanguageDefinitions.scoreMetaDataSignatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { NoteOrnament } from '@coderline/alphatab/model/NoteOrnament';
import { Ottavia } from '@coderline/alphatab/model/Ottavia';
import { PercussionMapper } from '@coderline/alphatab/model/PercussionMapper';
import { PickStroke } from '@coderline/alphatab/model/PickStroke';
import type { RenderStylesheet } from '@coderline/alphatab/model/RenderStylesheet';
import { BarNumberDisplay, type RenderStylesheet } from '@coderline/alphatab/model/RenderStylesheet';
import { HeaderFooterStyle, Score, ScoreStyle, ScoreSubElement } from '@coderline/alphatab/model/Score';
import { Section } from '@coderline/alphatab/model/Section';
import { SimileMark } from '@coderline/alphatab/model/SimileMark';
Expand Down Expand Up @@ -274,6 +274,18 @@ export class AlphaTex1LanguageHandler implements IAlphaTexLanguageImportHandler
case 'showsinglestaffbrackets':
score.stylesheet.showSingleStaffBrackets = true;
return ApplyNodeResult.Applied;
case 'defaultbarnumberdisplay':
const barNumberDisplay = AlphaTex1LanguageHandler._parseEnumValue(
importer,
metaData.arguments!,
'bar number display',
AlphaTex1EnumMappings.barNumberDisplay
);
if (barNumberDisplay === undefined) {
return ApplyNodeResult.NotAppliedSemanticError;
}
score.stylesheet.barNumberDisplay = barNumberDisplay!;
return ApplyNodeResult.Applied;

default:
return ApplyNodeResult.NotAppliedUnrecognizedMarker;
Expand Down Expand Up @@ -855,6 +867,18 @@ export class AlphaTex1LanguageHandler implements IAlphaTexLanguageImportHandler
bar.masterBar.isDoubleBar = true;
bar.barLineRight = BarLineStyle.LightLight;
return ApplyNodeResult.Applied;
case 'barnumberdisplay':
const barNumberDisplay = AlphaTex1LanguageHandler._parseEnumValue(
importer,
metaData.arguments!,
'bar number display',
AlphaTex1EnumMappings.barNumberDisplay
);
if (barNumberDisplay === undefined) {
return ApplyNodeResult.NotAppliedSemanticError;
}
bar.barNumberDisplay = barNumberDisplay!;
return ApplyNodeResult.Applied;
default:
return ApplyNodeResult.NotAppliedUnrecognizedMarker;
}
Expand Down Expand Up @@ -2545,6 +2569,10 @@ export class AlphaTex1LanguageHandler implements IAlphaTexLanguageImportHandler
nodes.push(Atnf.meta('showSingleStaffBrackets'));
}

if (stylesheet.barNumberDisplay !== BarNumberDisplay.AllBars) {
nodes.push(Atnf.identMeta('defaultBarNumberDisplay', BarNumberDisplay[stylesheet.barNumberDisplay]));
}

// Unsupported:
// 'globaldisplaychorddiagramsontop',
// 'pertrackchorddiagramsontop',
Expand Down Expand Up @@ -2724,6 +2752,10 @@ export class AlphaTex1LanguageHandler implements IAlphaTexLanguageImportHandler
];
}

if (bar.barNumberDisplay !== undefined) {
nodes.push(Atnf.identMeta('barNumberDisplay', BarNumberDisplay[bar.barNumberDisplay]));
}

return nodes;
}
private static _buildStaffMetaDataNodes(nodes: AlphaTexMetaDataNode[], staff: Staff) {
Expand Down
Loading
Loading