Selaa lähdekoodia

refactor guitarPro -> octavePlusOne(Encoding)

sschmid 4 vuotta sitten
vanhempi
commit
8f77908f80

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

@@ -115,10 +115,10 @@ export class InstrumentReader {
    * Main CreateSheet: read the next XML Measure and save all data to the given [[SourceMeasure]].
    * @param currentMeasure
    * @param measureStartAbsoluteTimestamp - Using this instead of currentMeasure.AbsoluteTimestamp as it isn't set yet
-   * @param guitarPro
+   * @param octavePlusOne Software like Guitar Pro gives one octave too low, so we need to add one
    * @returns {boolean}
    */
-  public readNextXmlMeasure(currentMeasure: SourceMeasure, measureStartAbsoluteTimestamp: Fraction, guitarPro: boolean): boolean {
+  public readNextXmlMeasure(currentMeasure: SourceMeasure, measureStartAbsoluteTimestamp: Fraction, octavePlusOne: boolean): boolean {
     if (this.currentXmlMeasureIndex >= this.xmlMeasureList.length) {
       return false;
     }
@@ -389,7 +389,7 @@ export class InstrumentReader {
             xmlNode, noteDuration, typeDuration, noteTypeXml, normalNotes, restNote,
             this.currentStaffEntry, this.currentMeasure,
             measureStartAbsoluteTimestamp,
-            this.maxTieNoteFraction, isChord, guitarPro,
+            this.maxTieNoteFraction, isChord, octavePlusOne,
             printObject, isCueNote, isGraceNote, stemDirectionXml, tremoloStrokes, stemColorXml, noteheadColorXml,
             vibratoStrokes
           );
@@ -438,7 +438,7 @@ export class InstrumentReader {
               throw new MusicSheetReadingException(errorMsg + this.instrument.Name);
             }
           }
-          this.addAbstractInstruction(xmlNode, guitarPro);
+          this.addAbstractInstruction(xmlNode, octavePlusOne);
           if (currentFraction.Equals(new Fraction(0, 1)) &&
             this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode)) {
             this.saveAbstractInstructionList(this.instrument.Staves.length, true);

+ 5 - 4
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -134,7 +134,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         this.initializeReading(partList, partInst, instrumentReaders);
         let couldReadMeasure: boolean = true;
         this.currentFraction = new Fraction(0, 1);
-        let guitarPro: boolean = false;
+        let octavePlusOneEncoding: boolean = false; // GuitarPro and Sibelius give octaves -1 apparently
         let encoding: IXmlElement = root.element("identification");
         if (encoding) {
             encoding = encoding.element("encoding");
@@ -142,8 +142,8 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         if (encoding) {
             encoding = encoding.element("software");
         }
-        if (encoding !== undefined && encoding.value === "Guitar Pro 5") {
-            guitarPro = true;
+        if (encoding !== undefined && (encoding.value === "Guitar Pro 5")) { //|| encoding.value.startsWith("Sibelius")
+            octavePlusOneEncoding = true;
         }
 
         while (couldReadMeasure) {
@@ -154,7 +154,8 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
             this.currentMeasure = new SourceMeasure(this.completeNumberOfStaves, this.musicSheet.Rules);
             for (const instrumentReader of instrumentReaders) {
                 try {
-                    couldReadMeasure = couldReadMeasure && instrumentReader.readNextXmlMeasure(this.currentMeasure, this.currentFraction, guitarPro);
+                    couldReadMeasure = couldReadMeasure && instrumentReader.readNextXmlMeasure(
+                        this.currentMeasure, this.currentFraction, octavePlusOneEncoding);
                 } catch (e) {
                     const errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/InstrumentError", "Error while reading instruments.");
                     throw new MusicSheetReadingException(errorMsg, e);

+ 5 - 5
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -101,13 +101,13 @@ export class VoiceGenerator {
    * @param measureStartAbsoluteTimestamp
    * @param maxTieNoteFraction
    * @param chord
-   * @param guitarPro
+   * @param octavePlusOne Software like Guitar Pro gives one octave too low, so we need to add one
    * @param printObject whether the note should be rendered (true) or invisible (false)
    * @returns {Note}
    */
   public read(noteNode: IXmlElement, noteDuration: Fraction, typeDuration: Fraction, noteTypeXml: NoteType, normalNotes: number, restNote: boolean,
               parentStaffEntry: SourceStaffEntry, parentMeasure: SourceMeasure,
-              measureStartAbsoluteTimestamp: Fraction, maxTieNoteFraction: Fraction, chord: boolean, guitarPro: boolean,
+              measureStartAbsoluteTimestamp: Fraction, maxTieNoteFraction: Fraction, chord: boolean, octavePlusOne: boolean,
               printObject: boolean, isCueNote: boolean, isGraceNote: boolean, stemDirectionXml: StemDirectionType, tremoloStrokes: number,
               stemColorXml: string, noteheadColorXml: string, vibratoStrokes: boolean): Note {
     this.currentStaffEntry = parentStaffEntry;
@@ -117,7 +117,7 @@ export class VoiceGenerator {
     try {
       this.currentNote = restNote
         ? this.addRestNote(noteNode.element("rest"), noteDuration, noteTypeXml, normalNotes, printObject, isCueNote, noteheadColorXml)
-        : this.addSingleNote(noteNode, noteDuration, noteTypeXml, typeDuration, normalNotes, chord, guitarPro,
+        : this.addSingleNote(noteNode, noteDuration, noteTypeXml, typeDuration, normalNotes, chord, octavePlusOne,
                              printObject, isCueNote, isGraceNote, stemDirectionXml, tremoloStrokes, stemColorXml, noteheadColorXml, vibratoStrokes);
       // read lyrics
       const lyricElements: IXmlElement[] = noteNode.elements("lyric");
@@ -313,11 +313,11 @@ export class VoiceGenerator {
    * @param noteDuration
    * @param divisions
    * @param chord
-   * @param guitarPro
+   * @param octavePlusOne Software like Guitar Pro gives one octave too low, so we need to add one
    * @returns {Note}
    */
   private addSingleNote(node: IXmlElement, noteDuration: Fraction, noteTypeXml: NoteType, typeDuration: Fraction,
-                        normalNotes: number, chord: boolean, guitarPro: boolean,
+                        normalNotes: number, chord: boolean, octavePlusOne: boolean,
                         printObject: boolean, isCueNote: boolean, isGraceNote: boolean, stemDirectionXml: StemDirectionType, tremoloStrokes: number,
                         stemColorXml: string, noteheadColorXml: string, vibratoStrokes: boolean): Note {
     //log.debug("addSingleNote called");