Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use always width from layout for registering layout info #606

Merged
merged 4 commits into from
May 22, 2021
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
22 changes: 13 additions & 9 deletions src.compiler/csharp/CSharpAstTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export default class CSharpAstTransformer {
name: this._context.toPascalCase((d.name as ts.Identifier).text),
parameters: [],
returnType: this.createUnresolvedTypeNode(null, d.type ?? d, returnType),
visibility: this.mapVisibility(d.modifiers),
visibility: this.mapVisibility(d),
tsNode: d,
skipEmit: this.shouldSkip(d, true)
};
Expand Down Expand Up @@ -967,7 +967,7 @@ export default class CSharpAstTransformer {
name: propertyName,
nodeType: cs.SyntaxKind.PropertyDeclaration,
parent: parent,
visibility: this.mapVisibility(classElement.modifiers),
visibility: this.mapVisibility(classElement),
type: this.createUnresolvedTypeNode(null, classElement.type ?? classElement, returnType),
skipEmit: this.shouldSkip(classElement, false)
};
Expand Down Expand Up @@ -1038,7 +1038,7 @@ export default class CSharpAstTransformer {
name: propertyName,
nodeType: cs.SyntaxKind.PropertyDeclaration,
parent: parent,
visibility: this.mapVisibility(classElement.modifiers),
visibility: this.mapVisibility(classElement),
type: this.createUnresolvedTypeNode(null, classElement.type ?? classElement, returnType),
skipEmit: this.shouldSkip(classElement, false)
};
Expand Down Expand Up @@ -1091,7 +1091,7 @@ export default class CSharpAstTransformer {
parent: cs.ClassDeclaration | cs.InterfaceDeclaration,
classElement: ts.PropertyDeclaration
) {
const visibility = this.mapVisibility(classElement.modifiers);
const visibility = this.mapVisibility(classElement);
const type = this._context.typeChecker.getTypeAtLocation(classElement);
const csProperty: cs.PropertyDeclaration = {
parent: parent,
Expand Down Expand Up @@ -1203,7 +1203,7 @@ export default class CSharpAstTransformer {
name: this._context.toPascalCase((classElement.name as ts.Identifier).text),
parameters: [],
returnType: this.createUnresolvedTypeNode(null, classElement.type ?? classElement, returnType),
visibility: this.mapVisibility(classElement.modifiers),
visibility: this.mapVisibility(classElement),
tsNode: classElement,
skipEmit: this.shouldSkip(classElement, false)
};
Expand Down Expand Up @@ -1852,9 +1852,13 @@ export default class CSharpAstTransformer {

this._context.registerSymbol(csMethod);
}
protected mapVisibility(modifiers: ts.ModifiersArray | undefined): cs.Visibility {
if (modifiers) {
for (const m of modifiers) {
protected mapVisibility(node: ts.Node): cs.Visibility {
if(this._context.isInternal(node)) {
return cs.Visibility.Internal;
}

if (node.modifiers) {
for (const m of node.modifiers) {
switch (m.kind) {
case ts.SyntaxKind.PublicKeyword:
return cs.Visibility.Public;
Expand Down Expand Up @@ -1913,7 +1917,7 @@ export default class CSharpAstTransformer {
name: '.ctor',
parameters: [],
isStatic: false,
visibility: this.mapVisibility(classElement.modifiers),
visibility: this.mapVisibility(classElement),
tsNode: classElement,
skipEmit: this.shouldSkip(classElement, false)
};
Expand Down
39 changes: 23 additions & 16 deletions src.compiler/csharp/CSharpEmitterContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class CSharpEmitterContext {
}

public registerUnresolvedTypeNode(unresolved: cs.UnresolvedTypeNode) {
if(this.processingSkippedElement) {
if (this.processingSkippedElement) {
return;
}
this._unresolvedTypeNodes.push(unresolved);
Expand Down Expand Up @@ -479,7 +479,11 @@ export default class CSharpEmitterContext {
return this.createBasicFunctionType(node, returnType, parameterTypes);
}

protected createBasicFunctionType(node:cs.Node, returnType: cs.TypeNode, parameterTypes: cs.TypeNode[]): cs.TypeNode {
protected createBasicFunctionType(
node: cs.Node,
returnType: cs.TypeNode,
parameterTypes: cs.TypeNode[]
): cs.TypeNode {
return {
nodeType: cs.SyntaxKind.FunctionTypeNode,
parent: node.parent,
Expand All @@ -488,7 +492,7 @@ export default class CSharpEmitterContext {
returnType: returnType
} as cs.FunctionTypeNode;
}

private resolveUnionType(
parent: cs.Node,
tsType: ts.Type,
Expand Down Expand Up @@ -784,12 +788,13 @@ export default class CSharpEmitterContext {
return text;
}

if(!text) {
if (!text) {
return '';
}

return text.split('.')
.map(p=> p.substr(0, 1).toUpperCase() + p.substr(1))
return text
.split('.')
.map(p => p.substr(0, 1).toUpperCase() + p.substr(1))
.join('.');
}

Expand Down Expand Up @@ -994,10 +999,12 @@ export default class CSharpEmitterContext {
symbol = this.typeChecker.getAliasedSymbol(symbol);
}

if (symbol.flags & ts.SymbolFlags.Interface ||
if (
symbol.flags & ts.SymbolFlags.Interface ||
symbol.flags & ts.SymbolFlags.Class ||
symbol.flags & ts.SymbolFlags.BlockScopedVariable ||
symbol.flags & ts.SymbolFlags.FunctionScopedVariable) {
symbol.flags & ts.SymbolFlags.FunctionScopedVariable
) {
return false;
}

Expand Down Expand Up @@ -1176,11 +1183,7 @@ export default class CSharpEmitterContext {
return this.hasAnyBaseTypeClassMember(classType, classElement.name!.getText());
}

protected hasAnyBaseTypeClassMember(
classType: ts.Type,
memberName: string,
allowInterfaces: boolean = false
) {
protected hasAnyBaseTypeClassMember(classType: ts.Type, memberName: string, allowInterfaces: boolean = false) {
const baseTypes = classType.getBaseTypes();
if (!baseTypes) {
return false;
Expand Down Expand Up @@ -1211,10 +1214,10 @@ export default class CSharpEmitterContext {
}

public isValueTypeExpression(expression: ts.NonNullExpression) {
let tsType:ts.Type;
if(ts.isIdentifier(expression.expression)) {
let tsType: ts.Type;
if (ts.isIdentifier(expression.expression)) {
const symbol = this.typeChecker.getSymbolAtLocation(expression.expression);
if(symbol?.valueDeclaration) {
if (symbol?.valueDeclaration) {
tsType = this.typeChecker.getTypeAtLocation(symbol.valueDeclaration);
} else {
tsType = this.typeChecker.getTypeAtLocation(expression);
Expand Down Expand Up @@ -1243,6 +1246,10 @@ export default class CSharpEmitterContext {
return false;
}

public isInternal(node: ts.Node) {
return !!ts.getJSDocTags(node).find(t => t.tagName.text === 'internal');
}

public rewriteVisibilities() {
const visited: Set<SymbolKey> = new Set();
for (const kvp of this._symbolLookup) {
Expand Down
24 changes: 19 additions & 5 deletions src.csharp/AlphaTab.Test/VisualTests/VisualTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace AlphaTab.VisualTests
partial class VisualTestHelper
{
public static async Task RunVisualTest(string inputFile, Settings? settings = null,
IList<double>? tracks = null, string? message = null, double tolerancePercent = 1)
IList<double>? tracks = null, string? message = null, double tolerancePercent = 1, bool triggerResize = false)
{
try
{
Expand All @@ -27,7 +27,7 @@ public static async Task RunVisualTest(string inputFile, Settings? settings = nu
var score = ScoreLoader.LoadScoreFromBytes(inputFileData, settings);

await RunVisualTestScore(score, referenceFileName, settings,
tracks, message, tolerancePercent);
tracks, message, tolerancePercent, triggerResize);
}
catch (Exception e)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ await RunVisualTestScore(score, referenceFileName, settings,

public static async Task RunVisualTestScore(Score score, string referenceFileName,
Settings? settings = null,
IList<double>? tracks = null, string? message = null, double tolerancePercent = 1)
IList<double>? tracks = null, string? message = null, double tolerancePercent = 1, bool triggerResize = false)
{
settings ??= new Settings();
tracks ??= new Core.List<double> {0};
Expand Down Expand Up @@ -92,13 +92,19 @@ public static async Task RunVisualTestScore(Score score, string referenceFileNam
var result = new AlphaTab.Core.List<RenderFinishedEventArgs>();
var totalWidth = 0.0;
var totalHeight = 0.0;
var isResizeRender = false;

var task = new TaskCompletionSource<object?>();
var renderer = new ScoreRenderer(settings)
{
Width = 1300
};

renderer.PreRender.On(isResize =>
{
result = new AlphaTab.Core.List<RenderFinishedEventArgs>();
totalWidth = 0.0;
totalHeight = 0.0;
});
renderer.PartialRenderFinished.On(e =>
{
if (e != null)
Expand All @@ -111,7 +117,15 @@ public static async Task RunVisualTestScore(Score score, string referenceFileNam
totalWidth = e.TotalWidth;
totalHeight = e.TotalHeight;
result.Add(e);
task.SetResult(null);
if(!triggerResize || isResizeRender)
{
task.SetResult(null);
}
else if(triggerResize)
{
isResizeRender = true;
renderer.ResizeRender();
}
});
renderer.Error.On((e) => { task.SetException(e); });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class VisualTestHelperPartials {
settings: Settings? = null,
tracks: MutableList<Double>? = null,
message: String? = null,
tolerancePercent: Double = 1.0
tolerancePercent: Double = 1.0,
triggerResize: Boolean = false
) {
try {
val fullInputFile = "test-data/visual-tests/$inputFile"
Expand All @@ -46,7 +47,8 @@ class VisualTestHelperPartials {
settings,
tracks,
message,
tolerancePercent
tolerancePercent,
triggerResize
)
} catch (e: Throwable) {
Assert.fail("Failed to run visual test $e")
Expand Down Expand Up @@ -86,7 +88,8 @@ class VisualTestHelperPartials {
settings: Settings? = null,
tracks: MutableList<Double>? = null,
message: String? = null,
tolerancePercent: Double = 1.0
tolerancePercent: Double = 1.0,
triggerResize: Boolean = false
) {
val actualSettings = settings ?: Settings()
val actualTracks = tracks ?: ArrayList()
Expand Down Expand Up @@ -116,9 +119,10 @@ class VisualTestHelperPartials {

val referenceFileData = TestPlatformPartials.loadFile(actualReferenceFileName)

val result = ArrayList<RenderFinishedEventArgs>()
var result = ArrayList<RenderFinishedEventArgs>()
var totalWidth = 0.0
var totalHeight = 0.0
var isResizeRender = false

val renderer = ScoreRenderer(actualSettings)
renderer.width = 1300.0
Expand All @@ -128,14 +132,25 @@ class VisualTestHelperPartials {

var error: Throwable? = null

renderer.preRender.on { _ ->
result = ArrayList<RenderFinishedEventArgs>()
totalWidth = 0.0
totalHeight = 0.0
}
renderer.partialRenderFinished.on { e ->
result.add(e)
}
renderer.renderFinished.on { e ->
totalWidth = e.totalWidth
totalHeight = e.totalHeight
result.add(e)
waitHandle.release()
if(!triggerResize || isResizeRender) {
waitHandle.release()
} else if(triggerResize) {
isResizeRender = true
renderer.resizeRender()
}

}
renderer.error.on { e ->
error = e
Expand Down
4 changes: 4 additions & 0 deletions src/AlphaTabApiBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ export class AlphaTabApiBase<TSettings> {
}
}

/**
* @internal
*/
private triggerResize(): void {
if (!this.container.isVisible) {
Logger.warning(
Expand Down Expand Up @@ -334,6 +337,7 @@ export class AlphaTabApiBase<TSettings> {
public tex(tex: string, tracks?: number[]): void {
try {
let parser: AlphaTexImporter = new AlphaTexImporter();
parser.logErrors = true;
parser.initFromString(tex, this.settings);
let score: Score = parser.readScore();
this.renderScore(score, tracks);
Expand Down
10 changes: 8 additions & 2 deletions src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export class AlphaTexImporter extends ScoreImporter {
private _staffHasExplicitTuning: boolean = false;
private _staffTuningApplied: boolean = false;

public logErrors:boolean = false;

public constructor() {
super();
}
Expand Down Expand Up @@ -197,13 +199,17 @@ export class AlphaTexImporter extends ScoreImporter {
} else {
e = AlphaTexError.symbolError(this._curChPos, nonterm, expected, expected, this._syData);
}
Logger.error(this.name, e.message!);
if(this.logErrors) {
Logger.error(this.name, e.message!);
}
throw e;
}

private errorMessage(message: string): void {
let e: AlphaTexError = AlphaTexError.errorMessage(this._curChPos, message);
Logger.error(this.name, e.message!);
if(this.logErrors) {
Logger.error(this.name, e.message!);
}
throw e;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/ScoreRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export class ScoreRenderer implements IScoreRenderer {
(this.preRender as EventEmitterOfT<boolean>).trigger(false);
this.recreateLayout();
this.layoutAndRender();
this._renderedTracks = this.tracks;
Logger.debug('Rendering', 'Rendering finished');
}

Expand Down Expand Up @@ -157,6 +156,7 @@ export class ScoreRenderer implements IScoreRenderer {
);
this.layout!.layoutAndRender();
this.layout!.renderAnnotation();
this._renderedTracks = this.tracks;
this.onRenderFinished();
(this.postRenderFinished as EventEmitter).trigger();
}
Expand Down
8 changes: 4 additions & 4 deletions src/rendering/glyphs/BeatContainerGlyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export class BeatContainerGlyph extends Glyph {
}

public registerLayoutingInfo(layoutings: BarLayoutingInfo): void {
let preBeatStretch: number = this.onTimeX;
let preBeatStretch: number = this.preNotes.computedWidth + this.onNotes.centerX;
if(this.beat.graceGroup && !this.beat.graceGroup.isComplete) {
preBeatStretch += BeatContainerGlyph.GraceBeatPadding * this.renderer.scale;
}

let postBeatStretch: number = this.onNotes.width - this.onNotes.centerX;
let postBeatStretch: number = this.onNotes.computedWidth - this.onNotes.centerX;
// make space for flag
const helper = this.renderer.helpers.getBeamingHelperForBeat(this.beat);
if(helper && helper.hasFlag || this.beat.graceType !== GraceType.None) {
Expand All @@ -57,8 +57,8 @@ export class BeatContainerGlyph extends Glyph {

layoutings.addBeatSpring(this.beat, preBeatStretch, postBeatStretch);
// store sizes for special renderers like the EffectBarRenderer
layoutings.setPreBeatSize(this.beat, this.preNotes.width);
layoutings.setOnBeatSize(this.beat, this.onNotes.width);
layoutings.setPreBeatSize(this.beat, this.preNotes.computedWidth);
layoutings.setOnBeatSize(this.beat, this.onNotes.computedWidth);
layoutings.setBeatCenterX(this.beat, this.onNotes.centerX);
}

Expand Down
Loading