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

feat(gp3-8): Beaming Modes and Ottava #1892

Merged
merged 9 commits into from
Feb 13, 2025
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
6 changes: 4 additions & 2 deletions src.compiler/TranspilerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ export default function (emitters: Emitter[], handleErrors: boolean = false) {
});
}

console.log('Done transpiling');

if (errorCount > 0) {
ts.sys.exit(ts.ExitStatus.DiagnosticsPresent_OutputsGenerated);
} else {
ts.sys.exit(ts.ExitStatus.Success);
}
} else{
console.log('Done transpiling');
}

console.log('Done');
}
16 changes: 15 additions & 1 deletion src/exporter/GpifWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AccentuationType } from '@src/model/AccentuationType';
import { AutomationType } from '@src/model/Automation';
import { Bar, SustainPedalMarkerType } from '@src/model/Bar';
import { BarreShape } from '@src/model/BarreShape';
import { Beat } from '@src/model/Beat';
import { Beat, BeatBeamingMode } from '@src/model/Beat';
import { BendPoint } from '@src/model/BendPoint';
import { BrushType } from '@src/model/BrushType';
import { Clef } from '@src/model/Clef';
Expand Down Expand Up @@ -740,9 +740,11 @@ export class GpifWriter {
switch (beat.preferredBeamDirection) {
case BeamDirection.Up:
beatNode.addElement('TransposedPitchStemOrientation').innerText = 'Upward';
beatNode.addElement('UserTransposedPitchStemOrientation').innerText = 'Upward';
break;
case BeamDirection.Down:
beatNode.addElement('TransposedPitchStemOrientation').innerText = 'Downward';
beatNode.addElement('UserTransposedPitchStemOrientation').innerText = 'Downward';
break;
}
}
Expand Down Expand Up @@ -788,6 +790,18 @@ export class GpifWriter {
if (beat.brushDuration > 0) {
this.writeSimpleXPropertyNode(beatProperties, '687935489', 'Int', beat.brushDuration.toString());
}

switch(beat.beamingMode) {
case BeatBeamingMode.ForceSplitToNext:
this.writeSimpleXPropertyNode(beatProperties, '1124204546', 'Int', "2");
break;
case BeatBeamingMode.ForceMergeWithNext:
this.writeSimpleXPropertyNode(beatProperties, '1124204546', 'Int', "1");
break;
case BeatBeamingMode.ForceSplitOnSecondaryToNext:
this.writeSimpleXPropertyNode(beatProperties, '1124204552', 'Int', "1");
break;
}
}

private writeBeatProperties(beatNode: XmlNode, beat: Beat) {
Expand Down
3 changes: 3 additions & 0 deletions src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,9 @@ export class AlphaTexImporter extends ScoreImporter {
case 'merge':
beat.beamingMode = BeatBeamingMode.ForceMergeWithNext;
break;
case 'splitsecondary':
beat.beamingMode = BeatBeamingMode.ForceSplitOnSecondaryToNext;
break;
}
this._sy = this.newSy();
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/importer/BinaryStylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class BinaryStylesheet {

public static writeForScore(score: Score): Uint8Array {
const writer = ByteBuffer.withCapacity(128);
IOHelper.writeInt32BE(writer, 3); // entry count
IOHelper.writeInt32BE(writer, 5); // entry count

BinaryStylesheet.writeBooleanEntry(writer, 'StandardNotation/hideDynamics', score.stylesheet.hideDynamics);
BinaryStylesheet.writeNumberEntry(writer, 'System/bracketExtendMode', score.stylesheet.bracketExtendMode as number);
Expand Down
76 changes: 70 additions & 6 deletions src/importer/Gp3To5Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IReadable } from '@src/io/IReadable';
import { AccentuationType } from '@src/model/AccentuationType';
import { Automation, AutomationType } from '@src/model/Automation';
import { Bar } from '@src/model/Bar';
import { Beat } from '@src/model/Beat';
import { Beat, BeatBeamingMode } from '@src/model/Beat';
import { BendPoint } from '@src/model/BendPoint';
import { BrushType } from '@src/model/BrushType';
import { Chord } from '@src/model/Chord';
Expand Down Expand Up @@ -44,6 +44,8 @@ import { Tuning } from '@src/model/Tuning';
import { FadeType } from '@src/model/FadeType';
import { Rasgueado } from '@src/model/Rasgueado';
import { Direction } from '@src/model/Direction';
import { BeamDirection } from '@src/rendering/utils/BeamDirection';
import { Ottavia } from '@src/model';

export class Gp3To5Importer extends ScoreImporter {
private static readonly VersionString: string = 'FICHIER GUITAR PRO ';
Expand Down Expand Up @@ -616,13 +618,75 @@ export class Gp3To5Importer extends ScoreImporter {
}
}
if (this._versionNumber >= 500) {
this.data.readByte();
let flag: number = this.data.readByte();
if ((flag & 0x08) !== 0) {
this.data.readByte();
// not 100% sure about the bits here but they look good in all test files.

const flags2 = IOHelper.readInt16LE(this.data);

// beam flags indicate how to handle beams connected to the previous beat,
// so we have to set the beaming mode on the previous beat!

// 1 - Break Beams
if ((flags2 & 0x01) !== 0) {
if (newBeat.index > 0) {
voice.beats[newBeat.index - 1].beamingMode = BeatBeamingMode.ForceSplitToNext;
}
}

// 2 - Force beams down
// this bit also set if we 'invert' a down-stem, but bit 8 will force the direction to up as both bits are set
if ((flags2 & 0x02) !== 0) {
newBeat.preferredBeamDirection = BeamDirection.Down;
}

// 4 - Force Beams
if ((flags2 & 0x04) !== 0) {
if (newBeat.index > 0) {
voice.beats[newBeat.index - 1].beamingMode = BeatBeamingMode.ForceMergeWithNext;
}
}
}

// 8 - Force beams up
if ((flags2 & 0x08) !== 0) {
newBeat.preferredBeamDirection = BeamDirection.Up;
}

// 16 - Ottava 8va
if ((flags2 & 0x10) !== 0) {
newBeat.ottava = Ottavia._8va;
}

// 32 - Ottava 8vb
if ((flags2 & 0x20) !== 0) {
newBeat.ottava = Ottavia._8vb;
}

// 64 - Ottava 15ma
if ((flags2 & 0x40) !== 0) {
newBeat.ottava = Ottavia._15ma;
}

// 128 - Unknown, upper bit of first byte, maybe a placeholder.

// 256 - Ottava 15mb
if ((flags2 & 0x100) !== 0) {
newBeat.ottava = Ottavia._15mb;
}

// 512 - Unknown
// 1024 - Unknown

// 2048 - Break Secondary Beams info set? -> read another byte for flag
if ((flags2 & 0x800) !== 0) {
const breakSecondaryBeams = this.data.readByte() != 0;
if (newBeat.index > 0 && breakSecondaryBeams) {
voice.beats[newBeat.index - 1].beamingMode = BeatBeamingMode.ForceSplitOnSecondaryToNext;
}
}

// 4096 - Unknown
// 8096 - Force Tuplet Bracket
}

if (
beatTextAsLyrics &&
!newBeat.isRest &&
Expand Down
33 changes: 32 additions & 1 deletion src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UnsupportedFormatError } from '@src/importer/UnsupportedFormatError';
import { AccentuationType } from '@src/model/AccentuationType';
import { Automation, AutomationType } from '@src/model/Automation';
import { Bar, SustainPedalMarker, SustainPedalMarkerType } from '@src/model/Bar';
import { Beat } from '@src/model/Beat';
import { Beat, BeatBeamingMode } from '@src/model/Beat';
import { BendPoint } from '@src/model/BendPoint';
import { BrushType } from '@src/model/BrushType';
import { Chord } from '@src/model/Chord';
Expand Down Expand Up @@ -1731,6 +1731,16 @@ export class GpifParser {
break;
}
break;
case 'UserTransposedPitchStemOrientation':
switch (c.innerText) {
case 'Downward':
beat.preferredBeamDirection = BeamDirection.Down;
break;
case 'Upward':
beat.preferredBeamDirection = BeamDirection.Up;
break;
}
break;
}
}
}
Expand Down Expand Up @@ -1761,6 +1771,27 @@ export class GpifParser {
let id: string = c.getAttribute('id');
let value: number = 0;
switch (id) {
case '1124204546':
value = parseInt(c.findChildElement('Int')!.innerText);
switch (value) {
case 1:
beat.beamingMode = BeatBeamingMode.ForceMergeWithNext;
break;
case 2:
beat.beamingMode = BeatBeamingMode.ForceSplitToNext;
break;
}
break;
case '1124204552':
value = parseInt(c.findChildElement('Int')!.innerText);
switch (value) {
case 1:
if (beat.beamingMode !== BeatBeamingMode.ForceSplitToNext) {
beat.beamingMode = BeatBeamingMode.ForceSplitOnSecondaryToNext;
}
break;
}
break;
case '1124204545':
value = parseInt(c.findChildElement('Int')!.innerText);
beat.invertBeamDirection = value === 1;
Expand Down
6 changes: 5 additions & 1 deletion src/model/Beat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export enum BeatBeamingMode {
/**
* Force a merge with the next beat.
*/
ForceMergeWithNext
ForceMergeWithNext,
/**
* Force a split to the next beat on the secondary beam.
*/
ForceSplitOnSecondaryToNext
}

/**
Expand Down
Loading