Sfoglia il codice sorgente

feat(color): color rest notes, parse note color attribute

sschmidTU 6 anni fa
parent
commit
b2e96fabfe

+ 10 - 9
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -223,6 +223,16 @@ export class VexFlowConverter {
             if (numDots < note.numberOfDots) {
                 numDots = note.numberOfDots;
             }
+
+            if (EngravingRules.Rules.ColoringEnabled) {
+                const noteheadColor: string = note.sourceNote.NoteheadColorXml;
+                if (noteheadColor) {
+                    noteheadStyles.push({fillStyle: noteheadColor, strokeStyle: noteheadColor});
+                } else {
+                    noteheadStyles.push(undefined);
+                }
+            }
+
             // if it is a rest:
             if (note.sourceNote.isRest()) {
                 keys = ["b/4"];
@@ -250,15 +260,6 @@ export class VexFlowConverter {
                 }
             }
 
-            if (EngravingRules.Rules.ColoringEnabled) {
-                const noteheadColor: string = note.sourceNote.NoteheadColorXml;
-                if (noteheadColor) {
-                    noteheadStyles.push({fillStyle: noteheadColor, strokeStyle: noteheadColor});
-                } else {
-                    noteheadStyles.push(undefined);
-                }
-            }
-
             const pitch: [string, string, ClefInstruction] = (note as VexFlowGraphicalNote).vfpitch;
             keys.push(pitch[0]);
             accidentals.push(pitch[1]);

+ 17 - 0
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -275,6 +275,23 @@ export class InstrumentReader {
             }
           }
 
+          let noteColorXml: string;
+          const noteColorAttr: Attr = xmlNode.attribute("color");
+          if (noteColorAttr) {
+            const noteColorValue: string = noteColorAttr.value;
+            if (noteColorValue.length === 7) { // #RGB hexa
+              noteColorXml = noteColorValue;
+            } else if (noteColorValue.length === 9) { // #ARGB hexa, first part alpha channel
+              noteColorXml = noteColorValue.substr(2);
+            }
+            if (noteheadColorXml === undefined) {
+              noteheadColorXml = noteColorXml;
+            }
+            if (stemColorXml === undefined) {
+              stemColorXml = noteColorXml;
+            }
+          }
+
           let musicTimestamp: Fraction = currentFraction.clone();
           if (isChord) {
             musicTimestamp = previousFraction.clone();

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

@@ -113,7 +113,7 @@ export class VoiceGenerator {
     //log.debug("read called:", restNote);
     try {
       this.currentNote = restNote
-        ? this.addRestNote(noteDuration, printObject, isCueNote)
+        ? this.addRestNote(noteDuration, printObject, isCueNote, noteheadColorXml)
         : this.addSingleNote(noteNode, noteDuration, chord, guitarPro,
                              printObject, isCueNote, stemDirectionXml, stemColorXml, noteheadColorXml);
       // read lyrics
@@ -442,11 +442,12 @@ export class VoiceGenerator {
    * @param divisions
    * @returns {Note}
    */
-  private addRestNote(noteDuration: Fraction, printObject: boolean = true, isCueNote: boolean = false): Note {
+  private addRestNote(noteDuration: Fraction, printObject: boolean, isCueNote: boolean, noteheadColorXml: string): Note {
     const restFraction: Fraction = Fraction.createFromFraction(noteDuration);
     const restNote: Note = new Note(this.currentVoiceEntry, this.currentStaffEntry, restFraction, undefined);
     restNote.PrintObject = printObject;
     restNote.IsCueNote = isCueNote;
+    restNote.NoteheadColorXml = noteheadColorXml;
     this.currentVoiceEntry.Notes.push(restNote);
     if (this.openBeam !== undefined) {
       this.openBeam.ExtendedNoteList.push(restNote);

+ 1 - 1
test/data/OSMD_function_test_color.musicxml

@@ -111,7 +111,7 @@
           <words default-y="60.00" font-weight="bold" font-size="16">No. 1</words>
           </direction-type>
         </direction>
-      <note>
+      <note color="#0000BB">
         <rest/>
         <duration>2</duration>
         <voice>1</voice>