Skip to content

Commit

Permalink
Merge pull request #1305 from rvilarl/prettier
Browse files Browse the repository at this point in the history
Auto fix from eslint / prettier.
  • Loading branch information
ronyeh authored Jan 30, 2022
2 parents e98a902 + 154e315 commit 68a55db
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/fonts/bravura_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const BravuraMetrics = {
verticalPadding: 8,
stemPadding: 2,
leftPadding: 5,
rightPadding: 6
rightPadding: 6,
},
stroke: {
arrowheadBlackDown: {
Expand Down
2 changes: 1 addition & 1 deletion src/fonts/gonville_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const GonvilleMetrics = {
verticalPadding: 8,
stemPadding: 2,
leftPadding: 5,
rightPadding: 6
rightPadding: 6,
},
textNote: {
point: 40,
Expand Down
2 changes: 1 addition & 1 deletion src/fonts/petaluma_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const PetalumaMetrics = {
verticalPadding: 8,
stemPadding: 2,
leftPadding: 5,
rightPadding: 6
rightPadding: 6,
},
stroke: {
arrowheadBlackDown: {
Expand Down
8 changes: 4 additions & 4 deletions src/frethandfinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Font, FontInfo, FontStyle, FontWeight } from './font';
import { Modifier, ModifierPosition } from './modifier';
import { ModifierContextState } from './modifiercontext';
import { StemmableNote } from './stemmablenote';
import { RuntimeError } from './util';
import { TextFormatter } from './textformatter';
import { Tables } from './tables';
import { TextFormatter } from './textformatter';
import { RuntimeError } from './util';

export class FretHandFinger extends Modifier {
static get CATEGORY(): string {
Expand Down Expand Up @@ -45,10 +45,10 @@ export class FretHandFinger extends Modifier {
const textFormatter = TextFormatter.create(num.textFont);
const textHeight = textFormatter.maxHeight;
if (num.position === ModifierPosition.ABOVE) {
state.top_text_line += (textHeight / Tables.STAVE_LINE_DISTANCE) + 0.5;
state.top_text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
}
if (num.position === ModifierPosition.BELOW) {
state.text_line += (textHeight / Tables.STAVE_LINE_DISTANCE) + 0.5;
state.text_line += textHeight / Tables.STAVE_LINE_DISTANCE + 0.5;
}

if (note !== prev_note) {
Expand Down
38 changes: 19 additions & 19 deletions src/stringnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class StringNumber extends Modifier {
style: FontStyle.NORMAL,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
static get metrics(): any {
return Tables.currentMusicFont().getMetrics().glyphs.stringNumber;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static get metrics(): any {
return Tables.currentMusicFont().getMetrics().glyphs.stringNumber;
}

// ## Static Methods
// Arrange string numbers inside a `ModifierContext`
Expand All @@ -45,7 +45,7 @@ export class StringNumber extends Modifier {
let prev_note = null;
let shift_left = 0;
let shift_right = 0;
let modLines = 0;
const modLines = 0;

for (let i = 0; i < nums.length; ++i) {
const num = nums[i];
Expand Down Expand Up @@ -81,7 +81,7 @@ export class StringNumber extends Modifier {
prev_note = note;
}

const glyphLine = (modLines === 0) ? props.line : modLines;
const glyphLine = modLines === 0 ? props.line : modLines;

nums_list.push({
pos,
Expand Down Expand Up @@ -207,26 +207,26 @@ export class StringNumber extends Modifier {
let dot_y = start.y + this.y_shift + this.y_offset;

switch (this.position) {
case Modifier.Position.ABOVE: {
case Modifier.Position.ABOVE:
{
const ys = note.getYs();
dot_y = ys.reduce((a, b) => a < b ? a : b);
dot_y = ys.reduce((a, b) => (a < b ? a : b));
if (note.hasStem() && stemDirection == Stem.UP) {
dot_y = stem_ext.topY + StringNumber.metrics.stemPadding;
}
dot_y -= this.radius + StringNumber.metrics.verticalPadding
+ this.text_line * Tables.STAVE_LINE_DISTANCE;
dot_y -= this.radius + StringNumber.metrics.verticalPadding + this.text_line * Tables.STAVE_LINE_DISTANCE;
}
break;
case Modifier.Position.BELOW: {
const ys: number[] = note.getYs();
dot_y = ys.reduce((a, b) => a > b ? a : b);
if (note.hasStem() && stemDirection == Stem.DOWN) {
dot_y = stem_ext.topY - StringNumber.metrics.stemPadding;
}
dot_y += this.radius + StringNumber.metrics.verticalPadding
+ this.text_line * Tables.STAVE_LINE_DISTANCE;
case Modifier.Position.BELOW:
{
const ys: number[] = note.getYs();
dot_y = ys.reduce((a, b) => (a > b ? a : b));
if (note.hasStem() && stemDirection == Stem.DOWN) {
dot_y = stem_ext.topY - StringNumber.metrics.stemPadding;
}
dot_y += this.radius + StringNumber.metrics.verticalPadding + this.text_line * Tables.STAVE_LINE_DISTANCE;
}
break;
break;
case Modifier.Position.LEFT:
dot_x -= this.radius / 2 + StringNumber.metrics.leftPadding;
break;
Expand Down
30 changes: 18 additions & 12 deletions tests/formatter_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import { StaveNote } from '../src/stavenote';
import { Stem } from '../src/stem';
import { StemmableNote } from '../src/stemmablenote';
import { StringNumber } from '../src/stringnumber';
import { Tuplet } from '../src/tuplet';
import { Voice } from '../src/voice';
import { VoiceTime } from '../src/voice';

import { Tables } from '../src/tables';
import { Tuplet } from '../src/tuplet';
import { Voice, VoiceTime } from '../src/voice';
import { MockTickable } from './mocks';

const FormatterTests = {
Expand Down Expand Up @@ -332,7 +330,7 @@ function alignedMixedElements(options: TestOptions): void {
const stave2 = new Stave(410, 200, 400);
const notes = [
new StaveNote({ keys: ['c/5'], duration: '8' })
.addModifier(0, new Accidental('##'))
.addModifier(0, new Accidental('##'))
.addModifier(0, new FretHandFinger('4').setPosition(ModifierPosition.BELOW))
.addModifier(0, new StringNumber('3').setPosition(ModifierPosition.BELOW))
.addModifier(0, new Articulation('a.').setPosition(ModifierPosition.BELOW))
Expand All @@ -342,9 +340,13 @@ function alignedMixedElements(options: TestOptions): void {
.addModifier(0, new Articulation('a@u').setPosition(ModifierPosition.BELOW))
.addModifier(0, new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.BOTTOM))
.addModifier(
0, new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('Sans-serif', 20, ''))
.addModifier(0,
new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('Sans-serif', 20, '')),
0,
new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('Sans-serif', 20, '')
)
.addModifier(
0,
new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.BOTTOM).setFont('Sans-serif', 20, '')
),
new StaveNote({ keys: ['c/5'], duration: '8', stem_direction: Stem.DOWN })
.addModifier(0, new StringNumber('3').setPosition(ModifierPosition.BELOW))
.addModifier(0, new Articulation('a.').setPosition(ModifierPosition.BELOW))
Expand All @@ -365,10 +367,14 @@ function alignedMixedElements(options: TestOptions): void {
.addModifier(0, new Articulation('am').setPosition(ModifierPosition.ABOVE))
.addModifier(0, new Articulation('a@u').setPosition(ModifierPosition.ABOVE))
.addModifier(0, new Annotation('yyyy').setVerticalJustification(AnnotationVerticalJustify.TOP))
.addModifier(0,
new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('Sans-serif', 20, ''))
.addModifier(0,
new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('Sans-serif', 20, '')),
.addModifier(
0,
new Annotation('xxxx').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('Sans-serif', 20, '')
)
.addModifier(
0,
new Annotation('ttt').setVerticalJustification(AnnotationVerticalJustify.TOP).setFont('Sans-serif', 20, '')
),
new StaveNote({ keys: ['c/5'], duration: '8' }),
];

Expand Down

0 comments on commit 68a55db

Please sign in to comment.