Prechádzať zdrojové kódy

fix: fixed a bug in stem calculation which made all stems up for a single voice.

Matthias Uiberacker 7 rokov pred
rodič
commit
aeb670eb2c

+ 26 - 2
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -2135,8 +2135,32 @@ export abstract class MusicSheetCalculator {
                 // Linked voice: set stem down:
                 voiceEntry.StemDirection = StemDirectionType.Down;
             } else {
-                // if this voiceEntry belongs to the mainVoice: stem Up
-                voiceEntry.StemDirection = StemDirectionType.Up;
+                // if this voiceEntry belongs to the mainVoice:
+                // check first that there are also more voices present:
+                if (voiceEntry.ParentSourceStaffEntry.VoiceEntries.length > 1) {
+                    // as this voiceEntry belongs to the mainVoice: stem Up
+                    voiceEntry.StemDirection = StemDirectionType.Up;
+                }
+            }
+        }
+
+        // ToDo: shift code to end of measure to only check once for all beams
+        // check for a beam:
+        // if this voice entry currently has no desired direction yet:
+        if (voiceEntry.StemDirection === StemDirectionType.Undefined &&
+            voiceEntry.Notes.length > 0) {
+            const beam: Beam = voiceEntry.Notes[0].NoteBeam;
+            if (beam !== undefined) {
+                // if there is a beam, find any already set stemDirection in the beam:
+                for (const note of beam.Notes) {
+                    if (note.ParentVoiceEntry === voiceEntry) {
+                        continue;
+                    } else if (note.ParentVoiceEntry.StemDirection !== StemDirectionType.Undefined) {
+                        // set the stem direction
+                        voiceEntry.StemDirection = note.ParentVoiceEntry.StemDirection;
+                        break;
+                    }
+                }
             }
         }
     }