فهرست منبع

add TremoloStrokeScale and TremoloYSpacingScale in EngravingRules (#887)

sschmid 4 سال پیش
والد
کامیت
456d9da096

+ 4 - 0
src/MusicalScore/Graphical/EngravingRules.ts

@@ -164,6 +164,8 @@ export class EngravingRules {
     public ContinuousTempoTextHeight: number;
     public VexFlowDefaultNotationFontScale: number;
     public VexFlowDefaultTabFontScale: number;
+    public TremoloStrokeScale: number;
+    public TremoloYSpacingScale: number;
     public StaffLineWidth: number;
     public StaffLineColor: string;
     public LedgerLineWidth: number;
@@ -443,6 +445,8 @@ export class EngravingRules {
         // Line Widths
         this.VexFlowDefaultNotationFontScale = 39; // scales notes, including rests. default value 39 in Vexflow.
         this.VexFlowDefaultTabFontScale = 39;
+        this.TremoloStrokeScale = 1;
+        this.TremoloYSpacingScale = 1;
         this.StemWidth = 0.15; // originally 0.13. vexflow default 0.15. should probably be adjusted when increasing vexFlowDefaultNotationFontScale,
         this.StaffLineWidth = 0.10; // originally 0.12, but this will be pixels in Vexflow (*10).
         this.StaffLineColor = undefined; // if undefined, vexflow default (grey). not a width, but affects visual line clarity.

+ 4 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -428,7 +428,10 @@ export class VexFlowConverter {
             // add Tremolo strokes (only single note tremolos for now, Vexflow doesn't have beams for two-note tremolos yet)
             const tremoloStrokes: number = notes[i].sourceNote.TremoloStrokes;
             if (tremoloStrokes > 0) {
-                vfnote.addModifier(i, new Vex.Flow.Tremolo(tremoloStrokes));
+                const tremolo: Vex.Flow.Tremolo = new Vex.Flow.Tremolo(tremoloStrokes);
+                (tremolo as any).extra_stroke_scale = rules.TremoloStrokeScale;
+                (tremolo as any).y_spacing_scale = rules.TremoloYSpacingScale;
+                vfnote.addModifier(i, tremolo);
             }
         }
 

+ 72 - 0
src/VexFlowPatch/tremolo.js

@@ -0,0 +1,72 @@
+// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010.
+// Author: Mike Corrigan <corrigan@gmail.com>
+//
+// This class implements tremolo notation.
+
+import { Vex } from './vex';
+import { Modifier } from './modifier';
+import { Glyph } from './glyph';
+import { GraceNote } from './gracenote';
+
+export class Tremolo extends Modifier {
+  static get CATEGORY() { return 'tremolo'; }
+  static get YOFFSETSTEMUP() { return -9; }
+  static get YOFFSETSTEMDOWN() { return -21; }
+  static get XOFFSETSTEMUP() { return 6; }
+  static get XOFFSETSTEMDOWN() { return -2; }
+  constructor(num) {
+    super();
+    this.setAttribute('type', 'Tremolo');
+
+    this.num = num;
+    this.note = null;
+    this.index = null;
+    this.position = Modifier.Position.CENTER;
+    this.code = 'v74';
+
+    this.y_spacing_scale = 1;
+    this.extra_stroke_scale = 1;
+  }
+
+  getCategory() { return Tremolo.CATEGORY; }
+
+  draw() {
+    this.checkContext();
+
+    if (!(this.note && this.index != null)) {
+      throw new Vex.RERR('NoAttachedNote', "Can't draw Tremolo without a note and index.");
+    }
+
+    this.setRendered();
+    const stemDirection = this.note.getStemDirection();
+    this.y_spacing = 4 * stemDirection * this.y_spacing_scale;
+    const start = this.note.getModifierStartXY(this.position, this.index);
+    let x = start.x;
+    let y = this.note.stem.getExtents().topY;
+    let scale = this.note.getCategory() === 'gracenotes' ? GraceNote.SCALE : 1;
+    scale *= this.extra_stroke_scale;
+    if (stemDirection < 0) {
+      y += Tremolo.YOFFSETSTEMDOWN * scale;
+    } else {
+      y += Tremolo.YOFFSETSTEMUP * scale;
+    }
+
+    this.font = {
+      family: 'Arial',
+      size: 16 * scale,
+      weight: '',
+    };
+
+    this.render_options = {
+      font_scale: 35 * scale,
+      stroke_px: 3,
+      stroke_spacing: 10 * scale,
+    };
+
+    x += stemDirection < 0 ? Tremolo.XOFFSETSTEMDOWN : Tremolo.XOFFSETSTEMUP;
+    for (let i = 0; i < this.num; ++i) {
+      Glyph.renderGlyph(this.context, x, y, this.render_options.font_scale, this.code);
+      y += this.y_spacing;
+    }
+  }
+}