Skip to content

Commit

Permalink
feat: add Golpe
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Nov 10, 2024
1 parent 9586468 commit f1e535d
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 38 deletions.
22 changes: 16 additions & 6 deletions src/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import { FreeTimeEffectInfo } from './rendering/effects/FreeTimeEffectInfo';
import { ScoreBarRenderer } from './rendering/ScoreBarRenderer';
import { TabBarRenderer } from './rendering/TabBarRenderer';
import { SustainPedalEffectInfo } from './rendering/effects/SustainPedalEffectInfo';
import { GolpeEffectInfo } from './rendering/effects/GolpeEffectInfo';
import { GolpeType } from './model/GolpeType';

export class LayoutEngineFactory {
public readonly vertical: boolean;
Expand Down Expand Up @@ -102,7 +104,7 @@ export class Environment {
private static readonly StaffIdBeforeNumberedAlways = 'before-numbered-always';
private static readonly StaffIdBeforeTabAlways = 'before-tab-always';
private static readonly StaffIdBeforeTabHideable = 'before-tab-hideable';

private static readonly StaffIdBeforeEndAlways = 'before-end-always';

/**
* The font size of the music font in pixel.
Expand Down Expand Up @@ -515,7 +517,8 @@ export class Environment {
new SlightBeatVibratoEffectInfo(),
new WideNoteVibratoEffectInfo(),
new SlightNoteVibratoEffectInfo(),
new LeftHandTapEffectInfo()
new LeftHandTapEffectInfo(),
new GolpeEffectInfo(GolpeType.Finger)
],
(_, staff) => staff.showStandardNotation
),
Expand All @@ -527,6 +530,7 @@ export class Environment {
new CrescendoEffectInfo(),
new OttaviaEffectInfo(false),
new DynamicsEffectInfo(),
new GolpeEffectInfo(GolpeType.Thumb, (s, b) => b.voice.bar.staff.showStandardNotation),
new SustainPedalEffectInfo()
]),
// no before-numbered-hideable
Expand Down Expand Up @@ -558,11 +562,15 @@ export class Environment {
new PalmMuteEffectInfo(),
new PickStrokeEffectInfo(),
new PickSlideEffectInfo(),
new LeftHandTapEffectInfo()
new LeftHandTapEffectInfo(),
new GolpeEffectInfo(GolpeType.Finger, (s, b) => !b.voice.bar.staff.showStandardNotation)
],
(_, staff) => staff.showTablature
),
new TabBarRendererFactory()
new TabBarRendererFactory(),
new EffectBarRendererFactory(Environment.StaffIdBeforeEndAlways, [
new GolpeEffectInfo(GolpeType.Thumb, (s, b) => !b.voice.bar.staff.showStandardNotation)
])
];
}

Expand All @@ -583,7 +591,8 @@ export class Environment {
Environment.StaffIdBeforeScoreAlways,
Environment.StaffIdBeforeNumberedAlways,
Environment.StaffIdBeforeTabAlways,
ScoreBarRenderer.StaffId
ScoreBarRenderer.StaffId,
Environment.StaffIdBeforeEndAlways
]);
staveProfiles.set(
StaveProfile.Score,
Expand All @@ -595,7 +604,8 @@ export class Environment {
Environment.StaffIdBeforeScoreAlways,
Environment.StaffIdBeforeNumberedAlways,
Environment.StaffIdBeforeTabAlways,
TabBarRenderer.StaffId
TabBarRenderer.StaffId,
Environment.StaffIdBeforeEndAlways
]);
staveProfiles.set(
StaveProfile.Tab,
Expand Down
15 changes: 12 additions & 3 deletions src/NotationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export enum TabRhythmMode {
/**
* Rhythm notation is shown and behaves like normal score notation with connected bars.
*/
ShowWithBars
ShowWithBars,
/**
* Automatic detection whether the tabs should show rhythm based on hidden standard notation.
*/
Automatic,
}

/**
Expand Down Expand Up @@ -297,7 +301,12 @@ export enum NotationElement {
/**
* The Sustain pedal effect shown above the staff "Ped.____*"
*/
EffectSustainPedal
EffectSustainPedal,

/**
* The Golpe effect signs above and below the saff.
*/
EffectGolpe
}

/**
Expand Down Expand Up @@ -334,7 +343,7 @@ export class NotationSettings {
/**
* Whether to show rhythm notation in the guitar tablature.
*/
public rhythmMode: TabRhythmMode = TabRhythmMode.Hidden;
public rhythmMode: TabRhythmMode = TabRhythmMode.Automatic;

/**
* The height of the rythm bars.
Expand Down
1 change: 1 addition & 0 deletions src/generated/model/BeatCloner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class BeatCloner {
clone.playbackStart = original.playbackStart;
clone.displayDuration = original.displayDuration;
clone.playbackDuration = original.playbackDuration;
clone.golpe = original.golpe;
clone.dynamics = original.dynamics;
clone.invertBeamDirection = original.invertBeamDirection;
clone.preferredBeamDirection = original.preferredBeamDirection;
Expand Down
5 changes: 5 additions & 0 deletions src/generated/model/BeatSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { VibratoType } from "@src/model/VibratoType";
import { GraceType } from "@src/model/GraceType";
import { PickStroke } from "@src/model/PickStroke";
import { CrescendoType } from "@src/model/CrescendoType";
import { GolpeType } from "@src/model/GolpeType";
import { DynamicValue } from "@src/model/DynamicValue";
import { BeamDirection } from "@src/rendering/utils/BeamDirection";
import { BeatBeamingMode } from "@src/model/Beat";
Expand Down Expand Up @@ -72,6 +73,7 @@ export class BeatSerializer {
o.set("playbackstart", obj.playbackStart);
o.set("displayduration", obj.displayDuration);
o.set("playbackduration", obj.playbackDuration);
o.set("golpe", obj.golpe as number);
o.set("dynamics", obj.dynamics as number);
o.set("invertbeamdirection", obj.invertBeamDirection);
o.set("preferredbeamdirection", obj.preferredBeamDirection as number | null);
Expand Down Expand Up @@ -202,6 +204,9 @@ export class BeatSerializer {
case "playbackduration":
obj.playbackDuration = v! as number;
return true;
case "golpe":
obj.golpe = JsonHelper.parseEnum<GolpeType>(v, GolpeType)!;
return true;
case "dynamics":
obj.dynamics = JsonHelper.parseEnum<DynamicValue>(v, DynamicValue)!;
return true;
Expand Down
9 changes: 9 additions & 0 deletions src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { Settings } from '@src/Settings';
import { ByteBuffer } from '@src/io/ByteBuffer';
import { PercussionMapper } from '@src/model/PercussionMapper';
import { NoteAccidentalMode } from '@src/model';
import { GolpeType } from '@src/model/GolpeType';

/**
* A list of terminals recognized by the alphaTex-parser
Expand Down Expand Up @@ -1617,6 +1618,14 @@ export class AlphaTexImporter extends ScoreImporter {
beat.deadSlapped = true;
this._sy = this.newSy();
return true;
} else if (syData === 'glpf') {
this._sy = this.newSy();
beat.golpe = GolpeType.Finger;
return true;
} else if (syData === 'glpt') {
this._sy = this.newSy();
beat.golpe = GolpeType.Thumb;
return true;
} else {
// string didn't match any beat effect syntax
return false;
Expand Down
11 changes: 11 additions & 0 deletions src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { TextBaseline } from '@src/platform/ICanvas';
import { BeatCloner } from '@src/generated/model/BeatCloner';
import { NoteCloner } from '@src/generated/model/NoteCloner';
import { Logger } from '@src/Logger';
import { GolpeType } from '@src/model/GolpeType';

/**
* This structure represents a duration within a gpif
Expand Down Expand Up @@ -1615,6 +1616,16 @@ export class GpifParser {
case 'DeadSlapped':
beat.deadSlapped = true;
break;
case 'Golpe':
switch (c.innerText) {
case 'Finger':
beat.golpe = GolpeType.Finger;
break;
case 'Thumb':
beat.golpe = GolpeType.Thumb;
break;
}
break;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/model/Beat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Settings } from '@src/Settings';
import { BeamDirection } from '@src/rendering/utils/BeamDirection';
import { BeatCloner } from '@src/generated/model/BeatCloner';
import { GraceGroup } from '@src/model/GraceGroup';
import { GolpeType } from './GolpeType';

/**
* Lists the different modes on how beaming for a beat should be done.
Expand Down Expand Up @@ -400,6 +401,11 @@ export class Beat {
*/
public playbackDuration: number = 0;

/**
* The type of golpe to play.
*/
public golpe: GolpeType = GolpeType.None;

public get absoluteDisplayStart(): number {
return this.voice.bar.masterBar.start + this.displayStart;
}
Expand Down
19 changes: 19 additions & 0 deletions src/model/GolpeType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Lists all golpe types.
*/
export enum GolpeType {
/**
* No Golpe played.
*/
None,

/**
* Play a golpe with the thumb.
*/
Thumb,

/**
* Play a golpe with a finger.
*/
Finger
}
27 changes: 17 additions & 10 deletions src/rendering/TabBarRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TabBarRenderer extends LineBarRenderer {
public constructor(renderer: ScoreRenderer, bar: Bar) {
super(renderer, bar);

if(!bar.staff.showStandardNotation) {
if (!bar.staff.showStandardNotation) {
this.showTimeSignature = true;
this.showRests = true;
this.showTiedNotes = true;
Expand All @@ -51,10 +51,18 @@ export class TabBarRenderer extends LineBarRenderer {
return this.bar.staff.tuning.length;
}

public override get drawnLineCount(): number {
public override get drawnLineCount(): number {
return this.bar.staff.tuning.length;
}

public get rhythmMode() {
let mode = this.settings.notation.rhythmMode;
if (mode === TabRhythmMode.Automatic) {
mode = this.bar.staff.showStandardNotation ? TabRhythmMode.Hidden : TabRhythmMode.ShowWithBars;
}
return mode;
}

/**
* Gets the relative y position of the given steps relative to first line.
* @param line the line of the particular string where 0 is the most top line
Expand Down Expand Up @@ -95,15 +103,15 @@ export class TabBarRenderer extends LineBarRenderer {
}

protected override adjustSizes(): void {
if (this.settings.notation.rhythmMode !== TabRhythmMode.Hidden) {
if (this.rhythmMode !== TabRhythmMode.Hidden) {
this.height += this.settings.notation.rhythmHeight * this.settings.display.scale;
this.bottomPadding += this.settings.notation.rhythmHeight * this.settings.display.scale;
}
}

public override doLayout(): void {
super.doLayout();
if (this.settings.notation.rhythmMode !== TabRhythmMode.Hidden) {
if (this.rhythmMode !== TabRhythmMode.Hidden) {
this._hasTuplets = false;
for (let voice of this.bar.voices) {
if (this.hasVoiceContainer(voice)) {
Expand Down Expand Up @@ -156,8 +164,7 @@ export class TabBarRenderer extends LineBarRenderer {
this.bar.masterBar.timeSignatureNumerator,
this.bar.masterBar.timeSignatureDenominator,
this.bar.masterBar.timeSignatureCommon,
this.bar.masterBar.isFreeTime,

this.bar.masterBar.isFreeTime
)
);
}
Expand All @@ -173,17 +180,17 @@ export class TabBarRenderer extends LineBarRenderer {

public override paint(cx: number, cy: number, canvas: ICanvas): void {
super.paint(cx, cy, canvas);
if (this.settings.notation.rhythmMode !== TabRhythmMode.Hidden) {
if (this.rhythmMode !== TabRhythmMode.Hidden) {
this.paintBeams(cx, cy, canvas);
this.paintTuplets(cx, cy, canvas);
}
}

public override drawBeamHelperAsFlags(h: BeamingHelper): boolean {
return super.drawBeamHelperAsFlags(h) || this.settings.notation.rhythmMode === TabRhythmMode.ShowWithBeams;
return super.drawBeamHelperAsFlags(h) || this.rhythmMode === TabRhythmMode.ShowWithBeams;
}

protected override getFlagTopY(beat: Beat, _direction:BeamDirection): number {
protected override getFlagTopY(beat: Beat, _direction: BeamDirection): number {
const startGlyph: TabBeatGlyph = this.getOnNotesGlyphForBeat(beat) as TabBeatGlyph;
if (!startGlyph.noteNumbers || beat.duration === Duration.Half) {
return this.height - this.settings.notation.rhythmHeight * this.settings.display.scale - this.tupletSize;
Expand All @@ -192,7 +199,7 @@ export class TabBarRenderer extends LineBarRenderer {
}
}

protected override getFlagBottomY(_beat: Beat, _direction:BeamDirection): number {
protected override getFlagBottomY(_beat: Beat, _direction: BeamDirection): number {
return this.getFlagAndBarPos();
}

Expand Down
49 changes: 49 additions & 0 deletions src/rendering/effects/GolpeEffectInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { NotationElement } from '@src/NotationSettings';
import { EffectBarGlyphSizing } from '../EffectBarGlyphSizing';
import { Settings } from '@src/Settings';
import { Beat } from '@src/model';
import { GolpeType } from '@src/model/GolpeType';
import { EffectBarRendererInfo } from '../EffectBarRendererInfo';
import { BarRendererBase } from '../BarRendererBase';
import { EffectGlyph } from '../glyphs/EffectGlyph';
import { GuitarGolpeGlyph } from '../glyphs/GuitarGolpeGlyph';

export class GolpeEffectInfo extends EffectBarRendererInfo {
private _type: GolpeType;
private _shouldCreate?: (settings: Settings, beat: Beat) => boolean;

public constructor(type: GolpeType, shouldCreate?: (settings: Settings, beat: Beat) => boolean) {
super();
this._type = type;
this._shouldCreate = shouldCreate;
}

public get notationElement(): NotationElement {
return NotationElement.EffectGolpe;
}

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

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

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

public shouldCreateGlyph(settings: Settings, beat: Beat): boolean {
const shouldCreate = this._shouldCreate;
return beat.golpe == this._type && (!shouldCreate || shouldCreate(settings, beat));
}

public createNewGlyph(renderer: BarRendererBase, beat: Beat): EffectGlyph {
return new GuitarGolpeGlyph(0, 0, true);
}

public canExpand(from: Beat, to: Beat): boolean {
return false;
}
}
Loading

0 comments on commit f1e535d

Please sign in to comment.