Prechádzať zdrojové kódy

feat(parts): read and display XML part abbreviations (e.g. Vln for Violin)

sschmidTU 6 rokov pred
rodič
commit
9fe031e896

+ 9 - 3
src/MusicalScore/Graphical/MusicSystem.ts

@@ -281,10 +281,16 @@ export abstract class MusicSystem extends GraphicalObject {
                 const instrument: Instrument = instruments[idx];
                 let instrNameLabel: Label;
                 if (this !== this.parent.MusicSystems[0]) {
-                    if (!EngravingRules.Rules.RenderPartAbbreviations || this.Parent.Parent.ParentMusicSheet.Instruments.length === 1) {
-                        return; // don't render part abbreviations if there's only one instrument/part (could be an option in the future)
+                    if (!EngravingRules.Rules.RenderPartAbbreviations
+                        // don't render part abbreviations if there's only one instrument/part (could be an option in the future)
+                        || this.Parent.Parent.ParentMusicSheet.Instruments.length === 1
+                        || !instrument.PartAbbreviation
+                        || instrument.PartAbbreviation === "") {
+                        return;
                     }
-                    instrNameLabel = new Label(instrument.NameLabel.text[0] + ".", instrument.NameLabel.textAlignment, instrument.NameLabel.font);
+                    const labelText: string = instrument.PartAbbreviation;
+                    // const labelText: string = instrument.NameLabel.text[0] + ".";
+                    instrNameLabel = new Label(labelText, instrument.NameLabel.textAlignment, instrument.NameLabel.font);
                 } else {
                     instrNameLabel = instrument.NameLabel;
                 }

+ 8 - 0
src/MusicalScore/Instrument.ts

@@ -29,6 +29,7 @@ export class Instrument extends InstrumentalGroup {
 
     private lyricVersesNumbers: number[] = [];
     private subInstruments: SubInstrument[] = [];
+    private partAbbreviation: string;
 
     public get Voices(): Voice[] {
         return this.voices;
@@ -103,6 +104,13 @@ export class Instrument extends InstrumentalGroup {
         }
         return undefined;
     }
+    public get PartAbbreviation(): string {
+        return this.partAbbreviation;
+    }
+    public set PartAbbreviation(value: string) {
+        this.partAbbreviation = value;
+    }
+
     public get Visible(): boolean {
         if (this.voices.length > 0) {
             return this.Voices[0].Visible;

+ 2 - 0
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -719,6 +719,8 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                         try {
                             if (partElement.name === "part-name") {
                                 instrument.Name = partElement.value;
+                            } else if (partElement.name === "part-abbreviation") {
+                                instrument.PartAbbreviation = partElement.value;
                             } else if (partElement.name === "score-instrument") {
                                 const subInstrument: SubInstrument = new SubInstrument(instrument);
                                 subInstrument.idString = partElement.firstAttribute.value;

+ 1 - 1
src/OpenSheetMusicDisplay/OSMDOptions.ts

@@ -36,7 +36,7 @@ export interface IOSMDOptions {
     drawLyricist?: boolean;
     /** Whether to draw part (instrument) names. */
     drawPartNames?: boolean;
-    /** Whether to draw part (instrument) name abbreviations each system after the first for non-solo parts. Default true. */
+    /** Whether to draw part (instrument) name abbreviations each system after the first. Only draws if drawPartNames. Default true. */
     drawPartAbbreviations?: boolean;
     /** Whether to draw fingerings (only left to the note for now). Default true (unless solo part). */
     drawFingerings?: boolean;