liushengqiang 1 year ago
parent
commit
49ca59867c

+ 12 - 3
osmd-extended/src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -650,13 +650,22 @@ export class VexFlowConverter {
             }
             if (tremoloStrokes > 0 && TremoloType === 'stop') {
                 this.noteTremoloList.push(vfnote)
-                // console.log("🚀 ~ vfnote", vfnote)
+                // 全是全音符, 设置stem
+                const isAllWhole = this.noteTremoloList.filter(n => (n as any).duration === 'w').length === this.noteTremoloList.length
+                if (isAllWhole){
+                    try {
+                        if ((this.noteTremoloList[0] as any).keyProps && (this.noteTremoloList[1] as any).keyProps) {
+                            const _vfnote = (this.noteTremoloList[0] as any).keyProps[0].line > (this.noteTremoloList[1] as any).keyProps[0].line ? this.noteTremoloList[1] : this.noteTremoloList[0];
+                            (_vfnote as any).stem?.setResetHeight(30);
+                        }
+                    } catch (error) {
+                        console.error('设置都是全音符,stem的高度失败')
+                    }
+                }
                 const tremolo: VF.Tremolo = new VF.Tremolo(tremoloStrokes, [...this.noteTremoloList]);
                 (tremolo as any).extra_stroke_scale = 1.2;
                 (tremolo as any).y_spacing_scale = 1.2;
                 (tremolo as any).x_shift = -30;
-                // (tremolo as any).extra_stroke_scale = rules.TremoloStrokeScale;
-                // (tremolo as any).y_spacing_scale = rules.TremoloYSpacingScale;
                 vfnote.addModifier(i, tremolo);
                 this.noteTremoloList = []
             }

+ 3 - 22
osmd-extended/src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -70,7 +70,6 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
   /** space needed for a dash for lyrics spacing, calculated once */
   private dashSpace: number;
   public beamsNeedUpdate: boolean = false;
-  public isFirstZero: boolean = false
 
   constructor(rules: EngravingRules) {
     super();
@@ -969,19 +968,10 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
   
   protected calculateRehearsalMark(measure: SourceMeasure): void {
     const rehearsalExpression: RehearsalExpression = measure.rehearsalExpression;
-    // 修改 判断小节是否是从1开始
-    if (!this.isFirstZero && measure.MeasureNumber === 0){
-      this.isFirstZero = true;
-    }
     if (!rehearsalExpression) {
       return;
     }
-    const firstMeasureNumber: number = this.graphicalMusicSheet.MeasureList[0][0].MeasureNumber; // 0 for pickup, 1 otherwise
-    // 修改 使用MeasureNumber这里循环状态可能会有问题,使用measureListIndex可能稍微好一点,目前看来XML中的顺序的对的
-    // const measureNumber: number =  Math.max(measure.MeasureNumber - firstMeasureNumber, 0);
-    const measureNumber: number = Math.max(measure.measureListIndex + 1 - firstMeasureNumber, 0);
-    const staffNumber: number = 0;
-    const vfStave: VF.Stave = (this.graphicalMusicSheet.MeasureList[measureNumber][staffNumber] as VexFlowMeasure)?.getVFStave();
+    const vfStave: VF.Stave = (measure.VerticalMeasureList?.[0] as VexFlowMeasure)?.getVFStave?.();
     if (!vfStave) { // potentially multi measure rest
       return;
     }
@@ -990,10 +980,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
     if (measure.IsSystemStartMeasure) {
       xOffset += this.rules.RehearsalMarkXOffsetSystemStartMeasure;
     }
-    // const section: VF.StaveSection = new VF.StaveSection(rehearsalExpression.label, vfStave.getX(), yOffset);
-    // (vfStave as any).modifiers.push(section);
     const fontSize: number = this.rules.RehearsalMarkFontSize;
-    // console.log(rehearsalExpression.label, yOffset);
 
     // 修改 存在方块数字时,如果有反复标记,修改标记Y轴位置偏移
     const modifiers: VF.StaveModifier[] = vfStave.getModifiers();
@@ -1002,15 +989,10 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
       repetition.setShiftY(repetition.y_shift - 10)
     }
 
-    // 修改 小节数不对问题
-    if (this.isFirstZero) {
-      (vfStave as any).setSection(measure.MeasureNumberXML + 1 + '', yOffset, xOffset, fontSize); // fontSize is an extra argument from VexFlowPatch
-    } else {
-      (vfStave as any).setSection(rehearsalExpression.label, yOffset, xOffset, fontSize); // fontSize is an extra argument from VexFlowPatch
-    }
+    ;(vfStave as any).setSection(rehearsalExpression.label, yOffset, xOffset, fontSize); // fontSize is an extra argument from VexFlowPatch
 
     //修改 存在方块数字时,如果当前行有文字,修改文字Y轴位置偏移
-    if (this.graphicalMusicSheet.MeasureList[measureNumber][staffNumber]?.ParentStaffLine.AbstractExpressions){
+    if ((measure.VerticalMeasureList?.[0] as VexFlowMeasure)?.ParentStaffLine.AbstractExpressions){
       const staveSection: any = modifiers.find(n => n.getCategory().toLocaleLowerCase() === 'stavesection');
       for(let gue of measure?.VerticalMeasureList?.[0]?.ParentStaffLine?.AbstractExpressions || []){
         if (gue instanceof GraphicalUnknownExpression ){
@@ -1023,7 +1005,6 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         }
       }
     }
-
   }
 
   /**

+ 4 - 2
osmd-extended/src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -628,11 +628,13 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
         } else {
             // 修改 换行的渐强线错误
             try {
-                if (graphicalExpression.Lines.length === 2 && Math.abs(graphicalExpression.Lines[0].Start.x - graphicalExpression.Lines[1].Start.x) > 1){
+                if (graphicalExpression.Lines.length === 2 && Math.abs(graphicalExpression.Lines[0].Start.x - graphicalExpression.Lines[1].Start.x) > Number.EPSILON){
                     let minX = Math.min(...graphicalExpression.Lines.map(n => n.Start.x));
+                    let startYMin = Math.min(...graphicalExpression.Lines.map(n => n.Start.y));
                     graphicalExpression.Lines[0].Start.x = minX;
                     graphicalExpression.Lines[1].Start.x = minX;
-                    [graphicalExpression.Lines[0].Start.y, graphicalExpression.Lines[1].Start.y] = [graphicalExpression.Lines[1].Start.y, graphicalExpression.Lines[0].Start.y];
+                    graphicalExpression.Lines[0].Start.y = startYMin + this.rules.WedgeOpeningLength / 2;
+                    graphicalExpression.Lines[1].Start.y = startYMin + this.rules.WedgeOpeningLength * 2;
                     graphicalExpression.Lines[0].End.y += this.rules.WedgeOpeningLength / 2;
                     graphicalExpression.Lines[1].End.y += this.rules.WedgeOpeningLength;
                 }