|
@@ -16,16 +16,33 @@ import {FontStyles} from "../../../Common/Enums/FontStyles";
|
|
import {Fonts} from "../../../Common/Enums/Fonts";
|
|
import {Fonts} from "../../../Common/Enums/Fonts";
|
|
import {OutlineAndFillStyleEnum} from "../DrawingEnums";
|
|
import {OutlineAndFillStyleEnum} from "../DrawingEnums";
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Helper class, which contains static methods which actually convert
|
|
|
|
+ * from OSMD objects to VexFlow objects.
|
|
|
|
+ */
|
|
export class VexFlowConverter {
|
|
export class VexFlowConverter {
|
|
|
|
+ /**
|
|
|
|
+ * Mapping from numbers of alterations on the key signature to major keys
|
|
|
|
+ * @type {[alterationsNo: number]: string; }
|
|
|
|
+ */
|
|
private static majorMap: {[_: number]: string; } = {
|
|
private static majorMap: {[_: number]: string; } = {
|
|
"0": "C", 1: "G", 2: "D", 3: "A", 4: "E", 5: "B", 6: "F#", 7: "C#",
|
|
"0": "C", 1: "G", 2: "D", 3: "A", 4: "E", 5: "B", 6: "F#", 7: "C#",
|
|
8: "G#", "-1": "F", "-8": "Fb", "-7": "Cb", "-6": "Gb", "-5": "Db", "-4": "Ab", "-3": "Eb", "-2": "Bb",
|
|
8: "G#", "-1": "F", "-8": "Fb", "-7": "Cb", "-6": "Gb", "-5": "Db", "-4": "Ab", "-3": "Eb", "-2": "Bb",
|
|
};
|
|
};
|
|
|
|
+ /**
|
|
|
|
+ * Mapping from numbers of alterations on the key signature to minor keys
|
|
|
|
+ * @type {[alterationsNo: number]: string; }
|
|
|
|
+ */
|
|
private static minorMap: {[_: number]: string; } = {
|
|
private static minorMap: {[_: number]: string; } = {
|
|
"1": "E", "7": "A#", "0": "A", "6": "D#", "3": "F#", "-5": "Bb", "-4": "F", "-7": "Ab", "-6": "Eb",
|
|
"1": "E", "7": "A#", "0": "A", "6": "D#", "3": "F#", "-5": "Bb", "-4": "F", "-7": "Ab", "-6": "Eb",
|
|
"-1": "D", "4": "C#", "-3": "C", "-2": "G", "2": "B", "5": "G#", "-8": "Db", "8": "E#",
|
|
"-1": "D", "4": "C#", "-3": "C", "-2": "G", "2": "B", "5": "G#", "-8": "Db", "8": "E#",
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert a fraction to a string which represents a duration in VexFlow
|
|
|
|
+ * @param fraction a fraction representing the duration of a note
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
public static duration(fraction: Fraction): string {
|
|
public static duration(fraction: Fraction): string {
|
|
let dur: number = fraction.RealValue;
|
|
let dur: number = fraction.RealValue;
|
|
if (dur >= 1) {
|
|
if (dur >= 1) {
|
|
@@ -59,7 +76,7 @@ export class VexFlowConverter {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Converts AccidentalEnum to vexFlow accidental string
|
|
|
|
|
|
+ * Converts AccidentalEnum to a string which represents an accidental in VexFlow
|
|
* @param accidental
|
|
* @param accidental
|
|
* @returns {string}
|
|
* @returns {string}
|
|
*/
|
|
*/
|
|
@@ -86,7 +103,11 @@ export class VexFlowConverter {
|
|
return acc;
|
|
return acc;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert a set of GraphicalNotes to a VexFlow StaveNote
|
|
|
|
+ * @param notes form a chord on the staff
|
|
|
|
+ * @returns {Vex.Flow.StaveNote}
|
|
|
|
+ */
|
|
public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
|
|
public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
|
|
let keys: string[] = [];
|
|
let keys: string[] = [];
|
|
let accidentals: string[] = [];
|
|
let accidentals: string[] = [];
|
|
@@ -125,6 +146,12 @@ export class VexFlowConverter {
|
|
return vfnote;
|
|
return vfnote;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert a ClefInstruction to a string representing a clef type in VexFlow
|
|
|
|
+ * @param clef
|
|
|
|
+ * @returns {string}
|
|
|
|
+ * @constructor
|
|
|
|
+ */
|
|
public static Clef(clef: ClefInstruction): string {
|
|
public static Clef(clef: ClefInstruction): string {
|
|
let type: string;
|
|
let type: string;
|
|
switch (clef.ClefType) {
|
|
switch (clef.ClefType) {
|
|
@@ -148,6 +175,12 @@ export class VexFlowConverter {
|
|
return type;
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert a RhythmInstruction to a VexFlow TimeSignature object
|
|
|
|
+ * @param rhythm
|
|
|
|
+ * @returns {Vex.Flow.TimeSignature}
|
|
|
|
+ * @constructor
|
|
|
|
+ */
|
|
public static TimeSignature(rhythm: RhythmInstruction): Vex.Flow.TimeSignature {
|
|
public static TimeSignature(rhythm: RhythmInstruction): Vex.Flow.TimeSignature {
|
|
let timeSpec: string;
|
|
let timeSpec: string;
|
|
switch (rhythm.SymbolEnum) {
|
|
switch (rhythm.SymbolEnum) {
|
|
@@ -165,6 +198,11 @@ export class VexFlowConverter {
|
|
return new Vex.Flow.TimeSignature(timeSpec);
|
|
return new Vex.Flow.TimeSignature(timeSpec);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert a KeyInstruction to a string representing in VexFlow a key
|
|
|
|
+ * @param key
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
public static keySignature(key: KeyInstruction): string {
|
|
public static keySignature(key: KeyInstruction): string {
|
|
if (key === undefined) {
|
|
if (key === undefined) {
|
|
return undefined;
|
|
return undefined;
|
|
@@ -185,7 +223,13 @@ export class VexFlowConverter {
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Converts a lineType to a VexFlow StaveConnector type
|
|
|
|
+ * @param lineType
|
|
|
|
+ * @returns {any}
|
|
|
|
+ */
|
|
public static line(lineType: SystemLinesEnum): any {
|
|
public static line(lineType: SystemLinesEnum): any {
|
|
|
|
+ // TODO Not all line types are correctly mapped!
|
|
switch (lineType) {
|
|
switch (lineType) {
|
|
case SystemLinesEnum.SingleThin:
|
|
case SystemLinesEnum.SingleThin:
|
|
return Vex.Flow.StaveConnector.type.SINGLE;
|
|
return Vex.Flow.StaveConnector.type.SINGLE;
|
|
@@ -205,6 +249,13 @@ export class VexFlowConverter {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Construct a string which can be used in a CSS font property
|
|
|
|
+ * @param fontSize
|
|
|
|
+ * @param fontStyle
|
|
|
|
+ * @param font
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
public static font(fontSize: number, fontStyle: FontStyles = FontStyles.Regular, font: Fonts = Fonts.TimesNewRoman): string {
|
|
public static font(fontSize: number, fontStyle: FontStyles = FontStyles.Regular, font: Fonts = Fonts.TimesNewRoman): string {
|
|
let style: string = "normal";
|
|
let style: string = "normal";
|
|
let weight: string = "normal";
|
|
let weight: string = "normal";
|
|
@@ -239,8 +290,13 @@ export class VexFlowConverter {
|
|
return style + " " + weight + " " + Math.floor(fontSize) + "px " + family;
|
|
return style + " " + weight + " " + Math.floor(fontSize) + "px " + family;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Convert OutlineAndFillStyle to CSS properties
|
|
|
|
+ * @param styleId
|
|
|
|
+ * @returns {string}
|
|
|
|
+ */
|
|
public static style(styleId: OutlineAndFillStyleEnum): string {
|
|
public static style(styleId: OutlineAndFillStyleEnum): string {
|
|
- // TODO
|
|
|
|
|
|
+ // TODO To be implemented
|
|
return "purple";
|
|
return "purple";
|
|
}
|
|
}
|
|
}
|
|
}
|