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
2 changes: 2 additions & 0 deletions src/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { Settings } from './Settings';
import { AlphaTabError, AlphaTabErrorType } from './AlphaTabError';
import { SlashBarRendererFactory } from './rendering/SlashBarRendererFactory';
import { NumberedBarRendererFactory } from './rendering/NumberedBarRendererFactory';
import { FreeTimeEffectInfo } from './rendering/effects/FreeTimeEffectInfo';

export class LayoutEngineFactory {
public readonly vertical: boolean;
Expand Down Expand Up @@ -484,6 +485,7 @@ export class Environment {
new TempoEffectInfo(),
new TripletFeelEffectInfo(),
new MarkerEffectInfo(),
new FreeTimeEffectInfo(),
new TextEffectInfo(),
new ChordsEffectInfo()
]),
Expand Down
9 changes: 7 additions & 2 deletions src/NotationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export enum NotationElement {
* The track names which are shown in the accolade.
*/
TrackNames,

/**
* The chord diagrams for guitars. Usually shown
* below the score info.
Expand Down Expand Up @@ -287,7 +287,12 @@ export enum NotationElement {
/**
* The left hand tap symbol shown above the staff.
*/
EffectLeftHandTap
EffectLeftHandTap,

/**
* The "Free time" text shown above the staff.
*/
EffectFreeTime
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/exporter/GpifWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,12 @@ export class GpifWriter {
'Time'
).innerText = `${masterBar.timeSignatureNumerator}/${masterBar.timeSignatureDenominator}`;

if(masterBar.isFreeTime) {
masterBarNode.addElement(
'FreeTime'
);
}

let bars: string[] = [];
for (const tracks of masterBar.score.tracks) {
for (const staves of tracks.staves) {
Expand Down
4 changes: 4 additions & 0 deletions src/generated/model/MasterBarSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class MasterBarSerializer {
o.set("timesignaturenumerator", obj.timeSignatureNumerator);
o.set("timesignaturedenominator", obj.timeSignatureDenominator);
o.set("timesignaturecommon", obj.timeSignatureCommon);
o.set("isfreetime", obj.isFreeTime);
o.set("tripletfeel", obj.tripletFeel as number);
o.set("section", SectionSerializer.toJson(obj.section));
o.set("tempoautomations", obj.tempoAutomations.map(i => AutomationSerializer.toJson(i)));
Expand Down Expand Up @@ -80,6 +81,9 @@ export class MasterBarSerializer {
case "timesignaturecommon":
obj.timeSignatureCommon = v! as boolean;
return true;
case "isfreetime":
obj.isFreeTime = v! as boolean;
return true;
case "tripletfeel":
obj.tripletFeel = JsonHelper.parseEnum<TripletFeel>(v, TripletFeel)!;
return true;
Expand Down
17 changes: 11 additions & 6 deletions src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,10 @@ export class AlphaTexImporter extends ScoreImporter {
if (name === 'defaults') {
for (const [defaultName, defaultValue] of PercussionMapper.instrumentArticulationNames) {
this._percussionArticulationNames.set(defaultName.toLowerCase(), defaultValue);
this._percussionArticulationNames.set(AlphaTexImporter.toArticulationId(defaultName), defaultValue);
this._percussionArticulationNames.set(
AlphaTexImporter.toArticulationId(defaultName),
defaultValue
);
}
return true;
}
Expand All @@ -910,12 +913,12 @@ export class AlphaTexImporter extends ScoreImporter {
return false;
}
}

/**
* Encodes a given string to a shorthand text form without spaces or special characters
*/
private static toArticulationId(plain: string): string {
return plain.replace(new RegExp("[^a-zA-Z0-9]", "g"), "").toLowerCase()
return plain.replace(new RegExp('[^a-zA-Z0-9]', 'g'), '').toLowerCase();
}

private applyPercussionStaff(staff: Staff) {
Expand Down Expand Up @@ -1215,7 +1218,7 @@ export class AlphaTexImporter extends ScoreImporter {
}

private beat(voice: Voice): boolean {
// duration specifier?
// duration specifier?
this.beatDuration();

let beat: Beat = new Beat();
Expand Down Expand Up @@ -1506,7 +1509,7 @@ export class AlphaTexImporter extends ScoreImporter {
beat.crescendo = CrescendoType.Crescendo;
} else if (syData === 'dec') {
beat.crescendo = CrescendoType.Decrescendo;
} else if(syData === 'tempo') {
} else if (syData === 'tempo') {
// NOTE: playbackRatio is calculated on score finish when playback positions are known
const tempoAutomation = this.readTempoAutomation();
beat.automations.push(tempoAutomation);
Expand Down Expand Up @@ -1604,7 +1607,7 @@ export class AlphaTexImporter extends ScoreImporter {
fret = this._syData as number;
if (this._currentStaff.isPercussion && !PercussionMapper.instrumentArticulations.has(fret)) {
this.errorMessage(`Unknown percussion articulation ${fret}`);
}
}
break;
case AlphaTexSymbols.String:
if (this._currentStaff.isPercussion) {
Expand Down Expand Up @@ -1929,6 +1932,8 @@ export class AlphaTexImporter extends ScoreImporter {
}
master.timeSignatureDenominator = this._syData as number;
this._sy = this.newSy();
} else if (syData == 'ft') {
master.isFreeTime = true;
} else if (syData === 'ro') {
master.isRepeatStart = true;
this._sy = this.newSy();
Expand Down
3 changes: 3 additions & 0 deletions src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,9 @@ export class GpifParser {
masterBar.timeSignatureNumerator = parseInt(timeParts[0]);
masterBar.timeSignatureDenominator = parseInt(timeParts[1]);
break;
case 'FreeTime':
masterBar.isFreeTime = true;
break;
case 'DoubleBar':
masterBar.isDoubleBar = true;
break;
Expand Down
7 changes: 6 additions & 1 deletion src/model/MasterBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class MasterBar {
*/
public timeSignatureCommon: boolean = false;

/**
* Gets or sets whether the bar indicates a free time playing.
*/
public isFreeTime: boolean = false;

/**
* Gets or sets the triplet feel that is valid for this bar.
*/
Expand Down Expand Up @@ -148,7 +153,7 @@ export class MasterBar {
/**
* An absolute width of the bar to use when displaying in a multi-track layout.
*/
public displayWidth:number = -1;
public displayWidth: number = -1;

/**
* Calculates the time spent in this bar. (unit: midi ticks)
Expand Down
8 changes: 5 additions & 3 deletions src/rendering/NumberedBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,15 @@ export class NumberedBarRenderer extends LineBarRenderer {
private createTimeSignatureGlyphs(): void {
this.addPreBeatGlyph(new SpacingGlyph(0, 0, 5 * this.scale));

const masterBar = this.bar.masterBar;
this.addPreBeatGlyph(
new ScoreTimeSignatureGlyph(
0,
this.getLineY(0),
this.bar.masterBar.timeSignatureNumerator,
this.bar.masterBar.timeSignatureDenominator,
this.bar.masterBar.timeSignatureCommon
masterBar.timeSignatureNumerator,
masterBar.timeSignatureDenominator,
masterBar.timeSignatureCommon,
masterBar.isFreeTime && masterBar.previousMasterBar == null || masterBar.isFreeTime !== masterBar.previousMasterBar!.isFreeTime,
)
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/rendering/ScoreBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ export class ScoreBarRenderer extends LineBarRenderer {
(this.bar.previousBar &&
this.bar.masterBar.timeSignatureNumerator !== this.bar.previousBar.masterBar.timeSignatureNumerator) ||
(this.bar.previousBar &&
this.bar.masterBar.timeSignatureDenominator !== this.bar.previousBar.masterBar.timeSignatureDenominator)
this.bar.masterBar.timeSignatureDenominator !==
this.bar.previousBar.masterBar.timeSignatureDenominator) ||
(this.bar.previousBar &&
this.bar.masterBar.isFreeTime &&
this.bar.masterBar.isFreeTime !== this.bar.previousBar.masterBar.isFreeTime)
) {
this.createStartSpacing();
this.createTimeSignatureGlyphs();
Expand Down Expand Up @@ -470,7 +474,8 @@ export class ScoreBarRenderer extends LineBarRenderer {
this.getScoreY(lines),
this.bar.masterBar.timeSignatureNumerator,
this.bar.masterBar.timeSignatureDenominator,
this.bar.masterBar.timeSignatureCommon
this.bar.masterBar.timeSignatureCommon,
this.bar.masterBar.isFreeTime,
)
);
}
Expand Down Expand Up @@ -527,4 +532,4 @@ export class ScoreBarRenderer extends LineBarRenderer {
canvas.stroke();
canvas.lineWidth = this.scale;
}
}
}
8 changes: 5 additions & 3 deletions src/rendering/SlashBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ export class SlashBarRenderer extends LineBarRenderer {
private createTimeSignatureGlyphs(): void {
this.addPreBeatGlyph(new SpacingGlyph(0, 0, 5 * this.scale));

const masterBar = this.bar.masterBar;
this.addPreBeatGlyph(
new ScoreTimeSignatureGlyph(
0,
this.getLineY(0),
this.bar.masterBar.timeSignatureNumerator,
this.bar.masterBar.timeSignatureDenominator,
this.bar.masterBar.timeSignatureCommon
masterBar.timeSignatureNumerator,
masterBar.timeSignatureDenominator,
masterBar.timeSignatureCommon,
masterBar.isFreeTime && masterBar.previousMasterBar == null || masterBar.isFreeTime !== masterBar.previousMasterBar!.isFreeTime,
)
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/rendering/TabBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export class TabBarRenderer extends LineBarRenderer {
this.bar.previousBar.masterBar.timeSignatureNumerator) ||
(this.bar.previousBar &&
this.bar.masterBar.timeSignatureDenominator !==
this.bar.previousBar.masterBar.timeSignatureDenominator))
this.bar.previousBar.masterBar.timeSignatureDenominator) ||
(this.bar.previousBar &&
this.bar.masterBar.isFreeTime &&
this.bar.masterBar.isFreeTime !== this.bar.previousBar.masterBar.isFreeTime))
) {
this.createStartSpacing();
this.createTimeSignatureGlyphs();
Expand All @@ -146,7 +149,9 @@ export class TabBarRenderer extends LineBarRenderer {
this.getTabY(lines),
this.bar.masterBar.timeSignatureNumerator,
this.bar.masterBar.timeSignatureDenominator,
this.bar.masterBar.timeSignatureCommon
this.bar.masterBar.timeSignatureCommon,
this.bar.masterBar.isFreeTime,

)
);
}
Expand Down
45 changes: 45 additions & 0 deletions src/rendering/effects/FreeTimeEffectInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Beat } from '@src/model/Beat';
import { TextAlign } from '@src/platform/ICanvas';
import { BarRendererBase } from '@src/rendering/BarRendererBase';
import { EffectBarGlyphSizing } from '@src/rendering/EffectBarGlyphSizing';
import { EffectGlyph } from '@src/rendering/glyphs/EffectGlyph';
import { TextGlyph } from '@src/rendering/glyphs/TextGlyph';
import { EffectBarRendererInfo } from '@src/rendering/EffectBarRendererInfo';
import { Settings } from '@src/Settings';
import { NotationElement } from '@src/NotationSettings';

export class FreeTimeEffectInfo extends EffectBarRendererInfo {
public get notationElement(): NotationElement {
return NotationElement.EffectText;
}

public get hideOnMultiTrack(): boolean {
return false;
}

public get canShareBand(): boolean {
return true;
}

public get sizingMode(): EffectBarGlyphSizing {
return EffectBarGlyphSizing.SinglePreBeat;
}

public shouldCreateGlyph(settings: Settings, beat: Beat): boolean {
const masterBar = beat.voice.bar.masterBar;
const isFirstBeat = beat.voice.bar.staff.index === 0 && beat.voice.index === 0 && beat.index === 0;
return (
isFirstBeat &&
masterBar.isFreeTime &&
(masterBar.index === 0 || masterBar.isFreeTime != masterBar.previousMasterBar!.isFreeTime)
);
}

public createNewGlyph(renderer: BarRendererBase, beat: Beat): EffectGlyph {
return new TextGlyph(0, 0, 'Free time', renderer.resources.effectFont, TextAlign.Left);
}

public canExpand(from: Beat, to: Beat): boolean {
return true;
}
}
33 changes: 30 additions & 3 deletions src/rendering/glyphs/BarSeperatorGlyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ICanvas } from '@src/platform/ICanvas';
import { Glyph } from '@src/rendering/glyphs/Glyph';

export class BarSeperatorGlyph extends Glyph {
private static readonly DashSize: number = 4;

public constructor(x: number, y: number) {
super(x, y);
}
Expand Down Expand Up @@ -40,9 +42,34 @@ export class BarSeperatorGlyph extends Glyph {
!this.renderer.nextRenderer.bar.masterBar.isRepeatStart
) {
// small bar
canvas.fillRect(left + this.width - this.scale, top, this.scale, h);
if (this.renderer.bar.masterBar.isDoubleBar) {
canvas.fillRect(left + this.width - 5 * this.scale, top, this.scale, h);
if (this.renderer.bar.masterBar.isFreeTime) {
const dashSize: number = BarSeperatorGlyph.DashSize * this.scale;
const x = ((left + this.width - this.scale) | 0) + 0.5;
const dashes: number = Math.ceil(h / 2 / dashSize);

canvas.beginPath();
if (dashes < 1) {
canvas.moveTo(x, top);
canvas.lineTo(x, bottom);
} else {
let dashY = top;

// spread the dashes so they complete directly on the end-Y
const freeSpace = h - dashes * dashSize;
const freeSpacePerDash = freeSpace / (dashes - 1);

while (dashY < bottom) {
canvas.moveTo(x, dashY);
canvas.lineTo(x, dashY + dashSize);
dashY += dashSize + freeSpacePerDash;
}
}
canvas.stroke();
} else {
canvas.fillRect(left + this.width - this.scale, top, this.scale, h);
if (this.renderer.bar.masterBar.isDoubleBar) {
canvas.fillRect(left + this.width - 5 * this.scale, top, this.scale, h);
}
}
}
}
Expand Down
Loading