Ver Fonte

implemented setting a "wanted stem direction" in voice entry and added reading it for the stem direction of the vexflow stavenotes. (not working for now..)

Matthias Uiberacker há 7 anos atrás
pai
commit
d41f766275

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

@@ -16,7 +16,7 @@ import {FontStyles} from "../../../Common/Enums/FontStyles";
 import {Fonts} from "../../../Common/Enums/Fonts";
 import {OutlineAndFillStyleEnum, OUTLINE_AND_FILL_STYLE_DICT} from "../DrawingEnums";
 import {Logging} from "../../../Common/Logging";
-import { ArticulationEnum } from "../../VoiceData/VoiceEntry";
+import { ArticulationEnum, StemDirection } from "../../VoiceData/VoiceEntry";
 
 /**
  * Helper class, which contains static methods which actually convert
@@ -177,6 +177,17 @@ export class VexFlowConverter {
             duration: duration,
             keys: keys,
         });
+        const wantedStemDirection: StemDirection = notes[0].sourceNote.ParentVoiceEntry.stemDirection;
+        switch (wantedStemDirection) {
+            case(StemDirection.Up):
+                vfnote.setStemDirection(Vex.Flow.Stem.UP);
+                break;
+            case (StemDirection.Down):
+                vfnote.setStemDirection(Vex.Flow.Stem.DOWN);
+                break;
+            default:
+                break;
+        }
 
         const stemDirection: number = vfnote.getStemDirection();
 

+ 5 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -389,14 +389,17 @@ export class VexFlowMeasure extends StaffMeasure {
                 }
                 for (const beam of this.beams[voiceID]) {
                     const notes: Vex.Flow.StaveNote[] = [];
-                    for (const entry of beam[1]) {
+                    const staffEntries: VexFlowStaffEntry[] = beam[1];
+                    const autoStemBeam: boolean = staffEntries[0].graphicalNotes[voiceID][0].sourceNote.ParentVoiceEntry.stemDirection === undefined;
+                    for (const entry of staffEntries) {
                         const note: Vex.Flow.StaveNote = (<VexFlowStaffEntry>entry).vfNotes[voiceID];
                         if (note !== undefined) {
                           notes.push(note);
                         }
                     }
                     if (notes.length > 1) {
-                        vfbeams.push(new Vex.Flow.Beam(notes, true));
+                        const vfBeam: Vex.Flow.Beam = new Vex.Flow.Beam(notes, autoStemBeam);
+                        vfbeams.push(vfBeam);
                         // just a test for coloring the notes:
                         // for (let note of notes) {
                         //     (<Vex.Flow.StaveNote> note).setStyle({fillStyle: "green", strokeStyle: "green"});

+ 6 - 9
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -2,7 +2,7 @@ import {MusicSheetCalculator} from "../MusicSheetCalculator";
 import {VexFlowGraphicalSymbolFactory} from "./VexFlowGraphicalSymbolFactory";
 import {StaffMeasure} from "../StaffMeasure";
 import {StaffLine} from "../StaffLine";
-import {VoiceEntry} from "../../VoiceData/VoiceEntry";
+import {VoiceEntry, StemDirection} from "../../VoiceData/VoiceEntry";
 import {MusicSystem} from "../MusicSystem";
 import {GraphicalNote} from "../GraphicalNote";
 import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
@@ -166,12 +166,11 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
           // in case of StaffEntryLink don't check mainVoice / linkedVoice
           if (firstNote.sourceNote.ParentVoiceEntry === graphicalStaffEntry.sourceStaffEntry.VoiceEntries[0]) {
             // set stem up:
-            //graphicalStaffEntry.setStemDirection(firstNote, StemEnum.StemUp);
+            voiceEntry.stemDirection = StemDirection.Up;
             return;
           } else {
             // set stem down:
-            //const last: GraphicalNote = graphicalNotes[graphicalNotes.length - 1];
-            //graphicalStaffEntry.setStemDirection(last, StemEnum.StemDown);
+            voiceEntry.stemDirection = StemDirection.Down;
             return;
           }
         } else {
@@ -182,19 +181,17 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
 
             if (firstNote.sourceNote.ParentVoiceEntry.ParentVoice === mainVoice) {
               // set stem up:
-              //graphicalStaffEntry.setStemDirection(firstNote, StemEnum.StemUp);
+              voiceEntry.stemDirection = StemDirection.Up;
               return;
             } else {
               // two Voices present in same Measure
               // set stem down:
-              //const last: GraphicalNote = graphicalNotes[graphicalNotes.length - 1];
-              //graphicalStaffEntry.setStemDirection(last, StemEnum.StemDown);
+              voiceEntry.stemDirection = StemDirection.Down;
               return;
             }
           } else {
             // set stem down:
-            //const last: GraphicalNote = graphicalNotes[graphicalNotes.length - 1];
-            //graphicalStaffEntry.setStemDirection(last, StemEnum.StemDown);
+            voiceEntry.stemDirection = StemDirection.Down;
             return;
           }
         }

+ 7 - 0
src/MusicalScore/VoiceData/VoiceEntry.ts

@@ -29,6 +29,7 @@ export class VoiceEntry {
 
     public graceVoiceEntriesBefore: VoiceEntry[];
     public graceVoiceEntriesAfter: VoiceEntry[];
+    public stemDirection: StemDirection = undefined;
 
     private parentVoice: Voice;
     private parentSourceStaffEntry: SourceStaffEntry;
@@ -325,3 +326,9 @@ export enum ArticulationEnum {
     detachedlegato,
     otherarticulation
 }
+
+export enum StemDirection {
+    Up = 0,
+    Down = 1,
+    None = 2
+}