Kaynağa Gözat

PercussionOneLineXML position: fix wrong octave for non-single-staffline (#945)

diffs:
test_drum_tuplet_beams_measure1.musicxml_1 0.354052
test_drum_tuplet_flat_beams_Siebener_Endstreich_testFlam.musicxml_1 0.349178

original OSMD layout can still be used with osmd.rules.PercussionOneLineUseXMLDisplayStep = false
sschmid 4 yıl önce
ebeveyn
işleme
cd9d47f1da

+ 12 - 13
src/MusicalScore/Graphical/VexFlow/VexflowStafflineNoteCalculator.ts

@@ -89,7 +89,10 @@ export class VexflowStafflineNoteCalculator implements IStafflineNoteCalculator
             return graphicalNote;
         }
         const currentPitchList: Array<Pitch> = this.staffPitchListMapping.getValue(staffIndex);
-        const positionByXml: boolean = this.rules.PercussionOneLineUseXMLDisplayStep && graphicalNote.sourceNote.displayStepUnpitched !== undefined;
+        const xmlSingleStaffline: boolean = graphicalNote.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentStaff.StafflineCount === 1;
+        const positionByXml: boolean = this.rules.PercussionOneLineUseXMLDisplayStep &&
+            graphicalNote.sourceNote.displayStepUnpitched !== undefined &&
+            xmlSingleStaffline;
         if (currentPitchList.length > this.rules.PercussionOneLineCutoff && !positionByXml) {
             //Don't need to position notes. We aren't under the cutoff
             return graphicalNote;
@@ -97,24 +100,20 @@ export class VexflowStafflineNoteCalculator implements IStafflineNoteCalculator
         const vfGraphicalNote: VexFlowGraphicalNote = graphicalNote as VexFlowGraphicalNote;
         const notePitch: Pitch = graphicalNote.sourceNote.Pitch;
 
+        let displayNote: NoteEnum = this.baseLineNote;
+        let displayOctave: number = this.baseLineOctave;
+        if (this.rules.PercussionOneLineUseXMLDisplayStep
+            && graphicalNote.sourceNote.displayStepUnpitched !== undefined
+            && xmlSingleStaffline) {
+            displayNote = graphicalNote.sourceNote.displayStepUnpitched;
+            displayOctave = graphicalNote.sourceNote.displayOctaveUnpitched + this.rules.PercussionOneLineXMLDisplayStepOctaveOffset;
+        }
         //If we only need to render on one line
         if (currentPitchList.length <= this.rules.PercussionForceVoicesOneLineCutoff) {
-            let displayNote: NoteEnum = this.baseLineNote;
-            let displayOctave: number = this.baseLineOctave;
-            if (this.rules.PercussionOneLineUseXMLDisplayStep && graphicalNote.sourceNote.displayStepUnpitched !== undefined) {
-                displayNote = graphicalNote.sourceNote.displayStepUnpitched;
-                displayOctave = graphicalNote.sourceNote.displayOctaveUnpitched + this.rules.PercussionOneLineXMLDisplayStepOctaveOffset;
-            }
             vfGraphicalNote.setAccidental(new Pitch(displayNote, displayOctave, notePitch.Accidental));
         } else {
             const pitchIndex: number = VexflowStafflineNoteCalculator.PitchIndexOf(currentPitchList, notePitch);
             if (pitchIndex > -1) {
-                let displayNote: NoteEnum = this.baseLineNote;
-                let displayOctave: number = this.baseLineOctave;
-                if (this.rules.PercussionOneLineUseXMLDisplayStep && graphicalNote.sourceNote.displayStepUnpitched !== undefined) {
-                    displayNote = graphicalNote.sourceNote.displayStepUnpitched;
-                    displayOctave = graphicalNote.sourceNote.displayOctaveUnpitched + this.rules.PercussionOneLineXMLDisplayStepOctaveOffset;
-                }
                 const half: number = Math.ceil(currentPitchList.length / 2);
                 if (!this.rules.PercussionOneLineUseXMLDisplayStep) {
                     if (pitchIndex >= half) {

+ 8 - 3
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -41,7 +41,8 @@ export class VoiceGenerator {
     } else {
       this.voice = new Voice(instrument, voiceId);
     }
-    instrument.Voices.push(this.voice);
+    this.instrument = instrument;
+    this.instrument.Voices.push(this.voice);
     this.lyricsReader = new LyricsReader(this.musicSheet);
     this.articulationReader = new ArticulationReader();
   }
@@ -55,6 +56,7 @@ export class VoiceGenerator {
   private currentNote: Note;
   private currentMeasure: SourceMeasure;
   private currentStaffEntry: SourceStaffEntry;
+  private instrument: Instrument;
   // private lastBeamTag: string = "";
   private openBeams: Beam[] = []; // works like a stack, with push and pop
   private beamNumberOffset: number = 0;
@@ -387,10 +389,13 @@ export class VoiceGenerator {
           const octave: IXmlElement = noteElement.element("display-octave");
           if (octave) {
             noteOctave = parseInt(octave.value, 10);
-            displayOctaveUnpitched = noteOctave - 2;
-            if (guitarPro) {
+            displayOctaveUnpitched = noteOctave - 3;
+            if (octavePlusOne) {
               noteOctave += 1;
             }
+            if (this.instrument.Staves[0].StafflineCount === 1) {
+              displayOctaveUnpitched += 1;
+            }
           }
           if (displayStepElement) {
             noteStep = NoteEnum[displayStepElement.value.toUpperCase()];