Browse Source

cherry-picked from Tab Branch (Tab clef)

Matthias Uiberacker 7 years ago
parent
commit
21619aeae7

+ 7 - 2
src/MusicalScore/Graphical/MusicSystemBuilder.ts

@@ -3,7 +3,7 @@ import {GraphicalMusicPage} from "./GraphicalMusicPage";
 import {EngravingRules} from "./EngravingRules";
 import {RhythmInstruction} from "../VoiceData/Instructions/RhythmInstruction";
 import {KeyInstruction} from "../VoiceData/Instructions/KeyInstruction";
-import {ClefInstruction} from "../VoiceData/Instructions/ClefInstruction";
+import {ClefInstruction, ClefEnum} from "../VoiceData/Instructions/ClefInstruction";
 import {SourceMeasure} from "../VoiceData/SourceMeasure";
 import {MusicSystem} from "./MusicSystem";
 import {BoundingBox} from "./BoundingBox";
@@ -468,7 +468,12 @@ export class MusicSystemBuilder {
         let keyAdded: boolean = false;
         let rhythmAdded: boolean = false;
         if (currentClef !== undefined) {
-            measure.addClefAtBegin(currentClef);
+            if (measure.tabMeasure !== undefined) {
+                measure.tabMeasure.addClefAtBegin(currentClef);
+                measure.addClefAtBegin(new ClefInstruction(ClefEnum.G));
+            } else {
+                measure.addClefAtBegin(currentClef);
+            }
             clefAdded = true;
         } else {
             currentClef = this.activeClefs[visibleStaffIdx];

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

@@ -582,7 +582,8 @@ export class VexFlowConverter {
 
             // TAB Clef
             case ClefEnum.TAB:
-                type = "french";
+                // only used currently for creating the notes in the normal stave: There we need a normal treble clef
+                type = "treble";
                 break;
             default:
         }

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

@@ -4,7 +4,7 @@ import {SourceMeasure} from "../../VoiceData/SourceMeasure";
 import {Staff} from "../../VoiceData/Staff";
 import {StaffLine} from "../StaffLine";
 import {SystemLinesEnum} from "../SystemLinesEnum";
-import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
+import {ClefInstruction, ClefEnum} from "../../VoiceData/Instructions/ClefInstruction";
 import {KeyInstruction} from "../../VoiceData/Instructions/KeyInstruction";
 import {RhythmInstruction} from "../../VoiceData/Instructions/RhythmInstruction";
 import {VexFlowConverter} from "./VexFlowConverter";
@@ -144,8 +144,12 @@ export class VexFlowMeasure extends GraphicalMeasure {
      */
     public addClefAtBegin(clef: ClefInstruction): void {
         this.octaveOffset = clef.OctaveOffset;
+        if (clef.ClefType === ClefEnum.TAB) {
+            this.stave.addClef("tab", undefined, undefined, undefined);
+        } else {
         const vfclef: { type: string, size: string, annotation: string } = VexFlowConverter.Clef(clef, "default");
         this.stave.addClef(vfclef.type, vfclef.size, vfclef.annotation, Vex.Flow.StaveModifier.Position.BEGIN);
+        }
         this.updateInstructionWidth();
     }
 

+ 3 - 3
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -761,9 +761,6 @@ export class InstrumentReader {
           try {
             clefEnum = ClefEnum[signNode.value];
             if (!ClefInstruction.isSupportedClef(clefEnum)) {
-              if (clefEnum === ClefEnum.TAB && guitarPro) {
-                clefOctaveOffset = -1;
-              }
               errorMsg = ITextTranslation.translateText(
                 "ReaderErrorMessages/ClefError",
                 "Unsupported clef found -> using default clef."
@@ -772,6 +769,9 @@ export class InstrumentReader {
               clefEnum = ClefEnum.G;
               line = 2;
             }
+            if (clefEnum === ClefEnum.TAB) {
+              clefOctaveOffset = -1;
+            }
           } catch (e) {
             errorMsg = ITextTranslation.translateText(
               "ReaderErrorMessages/ClefError",

+ 3 - 3
src/MusicalScore/VoiceData/Instructions/ClefInstruction.ts

@@ -120,7 +120,7 @@ export class ClefInstruction extends AbstractNotationInstruction {
         if (this === undefined || other === undefined) {
             return false;
         }
-        return (this.ClefPitch === other.ClefPitch && this.Line === other.Line);
+        return (this.clefPitch === other.clefPitch && this.Line === other.Line);
     }
 
     public NotEqual(clef2: ClefInstruction): boolean {
@@ -150,8 +150,8 @@ export class ClefInstruction extends AbstractNotationInstruction {
                 this.referenceCyPosition = 2;
                 break;
             case ClefEnum.TAB:
-                this.clefPitch = new Pitch(NoteEnum.G, 2, AccidentalEnum.NONE);
-                this.referenceCyPosition = -1;
+                this.clefPitch = new Pitch(NoteEnum.G, 0, AccidentalEnum.NONE);
+                this.referenceCyPosition = 0;
                 break;
             default:
                 throw new ArgumentOutOfRangeException("clefType");