123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import Vex from "vexflow";
- import { BoundingBox } from "../BoundingBox";
- import { GraphicalStaffEntry } from "../GraphicalStaffEntry";
- import { VexFlowVoiceEntry } from "./VexFlowVoiceEntry";
- import { GraphicalPedal } from "../GraphicalPedal";
- import { Pedal } from "../../VoiceData/Expressions/ContinuousExpressions/Pedal";
- import { MusicSymbol } from "../MusicSymbol";
- import { GraphicalMeasure } from "../GraphicalMeasure";
- import { VexFlowMeasure } from "./VexFlowMeasure";
- /**
- * The vexflow adaptation of a pedal marking
- */
- export class VexFlowPedal extends GraphicalPedal {
- /** Defines the note where the pedal starts */
- public startNote: Vex.Flow.StemmableNote;
- /** Defines the note where the pedal ends */
- public endNote: Vex.Flow.StemmableNote;
- private vfStyle: Vex.Flow.PedalMarking.Styles = Vex.Flow.PedalMarking.Styles.BRACKET;
- public DepressText: string;
- public ReleaseText: string;
- public startVfVoiceEntry: VexFlowVoiceEntry;
- public endVfVoiceEntry: VexFlowVoiceEntry;
- public endMeasure: GraphicalMeasure;
- private line: number = -3;
- public EndSymbolPositionAndShape: BoundingBox = undefined;
- /**
- * Create a new vexflow pedal marking
- * @param pedal the object read by the ExpressionReader
- * @param parent the bounding box of the parent
- */
- constructor(pedal: Pedal, parent: BoundingBox, openBegin: boolean = false, openEnd: boolean = false) {
- super(pedal, parent);
- switch (this.pedalSymbol) {
- case MusicSymbol.PEDAL_SYMBOL:
- //This renders the pedal symbols in VF.
- this.vfStyle = Vex.Flow.PedalMarking.Styles.TEXT;
- this.EndSymbolPositionAndShape = new BoundingBox(this, parent);
- break;
- case MusicSymbol.PEDAL_MIXED:
- if (openBegin && openEnd) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).BRACKET_OPEN_BOTH;
- } else if (openBegin) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).BRACKET_OPEN_BEGIN;
- } else if (openEnd) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).MIXED_OPEN_END;
- } else {
- this.vfStyle = Vex.Flow.PedalMarking.Styles.MIXED;
- }
- break;
- case MusicSymbol.PEDAL_BRACKET:
- default:
- if (openBegin && openEnd) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).BRACKET_OPEN_BOTH;
- } else if (openBegin) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).BRACKET_OPEN_BEGIN;
- } else if (openEnd) {
- this.vfStyle = (Vex.Flow.PedalMarking.Styles as any).BRACKET_OPEN_END;
- } else {
- this.vfStyle = Vex.Flow.PedalMarking.Styles.BRACKET;
- }
- break;
- }
- }
- /**
- * Set a start note using a staff entry
- * @param graphicalStaffEntry the staff entry that holds the start note
- */
- public setStartNote(graphicalStaffEntry: GraphicalStaffEntry): boolean {
- for (const gve of graphicalStaffEntry.graphicalVoiceEntries) {
- const vve: VexFlowVoiceEntry = (gve as VexFlowVoiceEntry);
- if (vve?.vfStaveNote) {
- this.startNote = vve.vfStaveNote;
- this.startVfVoiceEntry = vve;
- return true;
- }
- }
- return false; // couldn't find a startNote
- }
- /**
- * Set an end note using a staff entry
- * @param graphicalStaffEntry the staff entry that holds the end note
- */
- public setEndNote(graphicalStaffEntry: GraphicalStaffEntry): boolean {
- // this is duplicate code from setStartNote, but if we make one general method, we add a lot of branching.
- if (!graphicalStaffEntry) {
- return false;
- }
- for (const gve of graphicalStaffEntry.graphicalVoiceEntries) {
- const vve: VexFlowVoiceEntry = (gve as VexFlowVoiceEntry);
- if (vve?.vfStaveNote) {
- this.endNote = vve.vfStaveNote;
- this.endVfVoiceEntry = vve;
- return true;
- }
- }
- return false; // couldn't find an endNote
- }
- public setEndMeasure(graphicalMeasure: GraphicalMeasure): void {
- this.endMeasure = graphicalMeasure;
- }
- public CalculateBoundingBox(): void {
- //TODO?
- }
- public setLine(line: number): void {
- this.line = line;
- }
- /**
- * Get the actual vexflow Pedal Marking used for drawing
- */
- public getPedalMarking(): Vex.Flow.PedalMarking {
- const pedalMarking: Vex.Flow.PedalMarking = new Vex.Flow.PedalMarking([this.startNote, this.endNote]);
- if (this.endMeasure) {
- (pedalMarking as any).setEndStave((this.endMeasure as VexFlowMeasure).getVFStave());
- }
- pedalMarking.setStyle(this.vfStyle);
- pedalMarking.setLine(this.line);
- pedalMarking.setCustomText(this.DepressText, this.ReleaseText);
- //If our end note is at the end of a stave, set that value
- if(this.endVfVoiceEntry?.parentStaffEntry?.parentMeasure?.parentSourceMeasure?.VerticalSourceStaffEntryContainers?.last() ===
- this.endVfVoiceEntry?.parentVoiceEntry?.ParentSourceStaffEntry?.VerticalContainerParent){
- (pedalMarking as any).EndsStave = true;
- }
- return pedalMarking;
- }
- }
|