12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714 |
- import { GraphicalStaffEntry } from "./GraphicalStaffEntry";
- import { StaffLine } from "./StaffLine";
- import { GraphicalMusicSheet } from "./GraphicalMusicSheet";
- import { EngravingRules } from "./EngravingRules";
- import { Tie } from "../VoiceData/Tie";
- import { Fraction } from "../../Common/DataObjects/Fraction";
- import { Note } from "../VoiceData/Note";
- import { MusicSheet } from "../MusicSheet";
- import { GraphicalMeasure } from "./GraphicalMeasure";
- import { ClefInstruction } from "../VoiceData/Instructions/ClefInstruction";
- import { LyricWord } from "../VoiceData/Lyrics/LyricsWord";
- import { SourceMeasure } from "../VoiceData/SourceMeasure";
- import { GraphicalMusicPage } from "./GraphicalMusicPage";
- import { GraphicalNote } from "./GraphicalNote";
- import { Beam } from "../VoiceData/Beam";
- import { OctaveEnum } from "../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
- import { VoiceEntry, StemDirectionType } from "../VoiceData/VoiceEntry";
- import { OrnamentContainer } from "../VoiceData/OrnamentContainer";
- import { ArticulationEnum } from "../VoiceData/VoiceEntry";
- import { Tuplet } from "../VoiceData/Tuplet";
- import { MusicSystem } from "./MusicSystem";
- import { GraphicalTie } from "./GraphicalTie";
- import { RepetitionInstruction } from "../VoiceData/Instructions/RepetitionInstruction";
- import { MultiExpression } from "../VoiceData/Expressions/MultiExpression";
- import { StaffEntryLink } from "../VoiceData/StaffEntryLink";
- import { MusicSystemBuilder } from "./MusicSystemBuilder";
- import { MultiTempoExpression } from "../VoiceData/Expressions/MultiTempoExpression";
- import { Repetition } from "../MusicSource/Repetition";
- import { PointF2D } from "../../Common/DataObjects/PointF2D";
- import { SourceStaffEntry } from "../VoiceData/SourceStaffEntry";
- import { BoundingBox } from "./BoundingBox";
- import { Instrument } from "../Instrument";
- import { GraphicalLabel } from "./GraphicalLabel";
- import { TextAlignmentEnum } from "../../Common/Enums/TextAlignment";
- import { VerticalGraphicalStaffEntryContainer } from "./VerticalGraphicalStaffEntryContainer";
- import { KeyInstruction } from "../VoiceData/Instructions/KeyInstruction";
- import { AbstractNotationInstruction } from "../VoiceData/Instructions/AbstractNotationInstruction";
- import { TechnicalInstruction } from "../VoiceData/Instructions/TechnicalInstruction";
- import { Pitch } from "../../Common/DataObjects/Pitch";
- import { LinkedVoice } from "../VoiceData/LinkedVoice";
- import { ColDirEnum } from "./BoundingBox";
- import { IGraphicalSymbolFactory } from "../Interfaces/IGraphicalSymbolFactory";
- import { ITextMeasurer } from "../Interfaces/ITextMeasurer";
- import { ITransposeCalculator } from "../Interfaces/ITransposeCalculator";
- import { OctaveShiftParams } from "./OctaveShiftParams";
- import { AccidentalCalculator } from "./AccidentalCalculator";
- import { MidiInstrument } from "../VoiceData/Instructions/ClefInstruction";
- import { Staff } from "../VoiceData/Staff";
- import { OctaveShift } from "../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
- import * as log from "loglevel";
- import Dictionary from "typescript-collections/dist/lib/Dictionary";
- import { GraphicalLyricEntry } from "./GraphicalLyricEntry";
- import { GraphicalLyricWord } from "./GraphicalLyricWord";
- import { GraphicalLine } from "./GraphicalLine";
- import { Label } from "../Label";
- import { GraphicalVoiceEntry } from "./GraphicalVoiceEntry";
- import { VerticalSourceStaffEntryContainer } from "../VoiceData/VerticalSourceStaffEntryContainer";
- import { SkyBottomLineCalculator } from "./SkyBottomLineCalculator";
- import { PlacementEnum } from "../VoiceData/Expressions/AbstractExpression";
- import { AbstractGraphicalInstruction } from "./AbstractGraphicalInstruction";
- import { GraphicalInstantaneousTempoExpression } from "./GraphicalInstantaneousTempoExpression";
- import { InstantaneousTempoExpression, TempoEnum } from "../VoiceData/Expressions/InstantaneousTempoExpression";
- import { ContinuousTempoExpression } from "../VoiceData/Expressions/ContinuousExpressions/ContinuousTempoExpression";
- import { FontStyles } from "../../Common/Enums/FontStyles";
- import { AbstractTempoExpression } from "../VoiceData/Expressions/AbstractTempoExpression";
- import { GraphicalInstantaneousDynamicExpression } from "./GraphicalInstantaneousDynamicExpression";
- import { ContDynamicEnum } from "../VoiceData/Expressions/ContinuousExpressions/ContinuousDynamicExpression";
- import { GraphicalContinuousDynamicExpression } from "./GraphicalContinuousDynamicExpression";
- /**
- * Class used to do all the calculations in a MusicSheet, which in the end populates a GraphicalMusicSheet.
- */
- export abstract class MusicSheetCalculator {
- public static symbolFactory: IGraphicalSymbolFactory;
- public static transposeCalculator: ITransposeCalculator;
- protected static textMeasurer: ITextMeasurer;
- protected staffEntriesWithGraphicalTies: GraphicalStaffEntry[] = [];
- protected staffEntriesWithOrnaments: GraphicalStaffEntry[] = [];
- protected staffEntriesWithChordSymbols: GraphicalStaffEntry[] = [];
- protected staffLinesWithLyricWords: StaffLine[] = [];
- protected graphicalLyricWords: GraphicalLyricWord[] = [];
- protected graphicalMusicSheet: GraphicalMusicSheet;
- protected rules: EngravingRules;
- //protected symbolFactory: IGraphicalSymbolFactory;
- public static get TextMeasurer(): ITextMeasurer {
- return MusicSheetCalculator.textMeasurer;
- }
- public static set TextMeasurer(value: ITextMeasurer) {
- MusicSheetCalculator.textMeasurer = value;
- }
- protected get leadSheet(): boolean {
- return this.graphicalMusicSheet.LeadSheet;
- }
- protected static setMeasuresMinStaffEntriesWidth(measures: GraphicalMeasure[], minimumStaffEntriesWidth: number): void {
- for (let idx: number = 0, len: number = measures.length; idx < len; ++idx) {
- const measure: GraphicalMeasure = measures[idx];
- measure.minimumStaffEntriesWidth = minimumStaffEntriesWidth;
- }
- }
- public initialize(graphicalMusicSheet: GraphicalMusicSheet): void {
- this.graphicalMusicSheet = graphicalMusicSheet;
- this.rules = graphicalMusicSheet.ParentMusicSheet.rules;
- this.prepareGraphicalMusicSheet();
- //this.calculate();
- }
- /**
- * Build the 2D [[GraphicalMeasure]] list needed for the [[MusicSheetCalculator]].
- * Internally it creates [[GraphicalMeasure]]s, [[GraphicalStaffEntry]]'s and [[GraphicalNote]]s.
- */
- public prepareGraphicalMusicSheet(): void {
- // Clear the stored system images dict - all systems have to be redrawn.
- // Not necessary now. TODO Check
- // this.graphicalMusicSheet.SystemImages.length = 0;
- const musicSheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
- this.staffEntriesWithGraphicalTies = [];
- this.staffEntriesWithOrnaments = [];
- this.staffEntriesWithChordSymbols = [];
- this.staffLinesWithLyricWords = [];
- // this.staffLinesWithGraphicalExpressions = [];
- this.graphicalMusicSheet.Initialize();
- const measureList: GraphicalMeasure[][] = this.graphicalMusicSheet.MeasureList;
- // one AccidentalCalculator for each Staff (regardless of Instrument)
- const accidentalCalculators: AccidentalCalculator[] = this.createAccidentalCalculators();
- // List of Active ClefInstructions
- const activeClefs: ClefInstruction[] = this.graphicalMusicSheet.initializeActiveClefs();
- // LyricWord - GraphicalLyricWord Lists
- const lyricWords: LyricWord[] = [];
- const completeNumberOfStaves: number = musicSheet.getCompleteNumberOfStaves();
- // Octave Shifts List
- const openOctaveShifts: OctaveShiftParams[] = [];
- // TieList - timestampsArray
- for (let i: number = 0; i < completeNumberOfStaves; i++) {
- openOctaveShifts.push(undefined);
- }
- // go through all SourceMeasures (taking into account normal SourceMusicParts and Repetitions)
- for (let idx: number = 0, len: number = musicSheet.SourceMeasures.length; idx < len; ++idx) {
- const sourceMeasure: SourceMeasure = musicSheet.SourceMeasures[idx];
- const graphicalMeasures: GraphicalMeasure[] = this.createGraphicalMeasuresForSourceMeasure(
- sourceMeasure,
- accidentalCalculators,
- lyricWords,
- openOctaveShifts,
- activeClefs
- );
- measureList.push(graphicalMeasures);
- }
- this.handleStaffEntries();
- this.calculateVerticalContainersList();
- this.setIndicesToVerticalGraphicalContainers();
- }
- /**
- * The main method for the Calculator.
- */
- public calculate(): void {
- this.clearSystemsAndMeasures();
- // delete graphicalObjects that will be recalculated and create the GraphicalObjects that strech over a single StaffEntry new.
- this.clearRecreatedObjects();
- this.createGraphicalTies();
- // calculate SheetLabelBoundingBoxes
- this.calculateSheetLabelBoundingBoxes();
- this.calculateXLayout(this.graphicalMusicSheet, this.maxInstrNameLabelLength());
- // create List<MusicPage>
- this.graphicalMusicSheet.MusicPages.length = 0;
- // create new MusicSystems and StaffLines (as many as necessary) and populate them with Measures from measureList
- this.calculateMusicSystems();
- // Add some white space at the end of the piece:
- this.graphicalMusicSheet.MusicPages[0].PositionAndShape.BorderMarginBottom += 9;
- // transform Relative to Absolute Positions
- GraphicalMusicSheet.transformRelativeToAbsolutePosition(this.graphicalMusicSheet);
- }
- public calculateXLayout(graphicalMusicSheet: GraphicalMusicSheet, maxInstrNameLabelLength: number): void {
- // for each inner List in big Measure List calculate new Positions for the StaffEntries
- // and adjust Measures sizes
- // calculate max measure length for maximum zoom in.
- let minLength: number = 0;
- const maxInstructionsLength: number = this.rules.MaxInstructionsConstValue;
- if (this.graphicalMusicSheet.MeasureList.length > 0) {
- /** list of vertically ordered measures belonging to one bar */
- let measures: GraphicalMeasure[] = this.graphicalMusicSheet.MeasureList[0];
- let minimumStaffEntriesWidth: number = this.calculateMeasureXLayout(measures);
- minimumStaffEntriesWidth = this.calculateMeasureWidthFromLyrics(measures, minimumStaffEntriesWidth);
- MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
- minLength = minimumStaffEntriesWidth * 1.2 + maxInstrNameLabelLength + maxInstructionsLength;
- for (let i: number = 1; i < this.graphicalMusicSheet.MeasureList.length; i++) {
- measures = this.graphicalMusicSheet.MeasureList[i];
- minimumStaffEntriesWidth = this.calculateMeasureXLayout(measures);
- minimumStaffEntriesWidth = this.calculateMeasureWidthFromLyrics(measures, minimumStaffEntriesWidth);
- MusicSheetCalculator.setMeasuresMinStaffEntriesWidth(measures, minimumStaffEntriesWidth);
- minLength = Math.max(minLength, minimumStaffEntriesWidth * 1.2 + maxInstructionsLength);
- }
- }
- this.graphicalMusicSheet.MinAllowedSystemWidth = minLength;
- }
- public calculateMeasureWidthFromLyrics(measuresVertical: GraphicalMeasure[], oldMinimumStaffEntriesWidth: number): number {
- throw new Error("abstract, not implemented");
- }
- protected formatMeasures(): void {
- throw new Error("abstract, not implemented");
- }
- /** Calculates the relative Positions of all MusicSystems.
- *
- */
- protected calculateMusicSystemsRelativePositions(graphicalMusicPage: GraphicalMusicPage): void {
- // xPosition is always fixed
- let relativePosition: PointF2D = new PointF2D(this.rules.PageLeftMargin + this.rules.SystemLeftMargin, 0);
- if (EngravingRules.Rules.CompactMode) {
- relativePosition.y += EngravingRules.Rules.PageTopMarginNarrow;
- } else {
- relativePosition.y += EngravingRules.Rules.PageTopMargin;
- }
- // first System is handled extra
- const firstMusicSystem: MusicSystem = graphicalMusicPage.MusicSystems[0];
- if (graphicalMusicPage === graphicalMusicPage.Parent.MusicPages[0]) {
- if (EngravingRules.Rules.RenderTitle) {
- relativePosition.y += this.rules.TitleTopDistance + this.rules.SheetTitleHeight +
- this.rules.TitleBottomDistance;
- }
- } else {
- if (EngravingRules.Rules.RenderTitle) {
- relativePosition.y += this.rules.PageTopMargin + this.rules.TitleTopDistance;
- } else {
- relativePosition.y = this.rules.PageTopMargin;
- }
- }
- firstMusicSystem.PositionAndShape.RelativePosition = relativePosition;
- for (let i: number = 1; i < graphicalMusicPage.MusicSystems.length; i++) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[i];
- relativePosition = new PointF2D(this.rules.PageLeftMargin + this.rules.SystemLeftMargin, 0);
- // find optimum distance between Systems
- const previousSystem: MusicSystem = graphicalMusicPage.MusicSystems[i - 1];
- const lastPreviousStaffLine: StaffLine = previousSystem.StaffLines[previousSystem.StaffLines.length - 1];
- const distance: number = (lastPreviousStaffLine.SkyBottomLineCalculator.getBottomLineMax() - this.rules.StaffHeight) +
- Math.abs(musicSystem.StaffLines[0].SkyBottomLineCalculator.getSkyLineMin()) +
- this.rules.MinimumAllowedDistanceBetweenSystems;
- relativePosition.y = previousSystem.PositionAndShape.RelativePosition.y +
- lastPreviousStaffLine.PositionAndShape.RelativePosition.y +
- this.rules.StaffHeight + Math.max(this.rules.SystemDistance, distance);
- musicSystem.PositionAndShape.RelativePosition = relativePosition;
- }
- }
- /**
- * Calculates the x layout of the staff entries within the staff measures belonging to one source measure.
- * All staff entries are x-aligned throughout all the measures.
- * @param measures - The minimum required x width of the source measure
- */
- protected calculateMeasureXLayout(measures: GraphicalMeasure[]): number {
- throw new Error("abstract, not implemented");
- }
- /**
- * This method checks the distances between two System's StaffLines and if needed, shifts the lower down.
- * @param musicSystem
- */
- protected optimizeDistanceBetweenStaffLines(musicSystem: MusicSystem): void {
- musicSystem.PositionAndShape.calculateAbsolutePositionsRecursive(0, 0);
- // don't perform any y-spacing in case of a StaffEntryLink (in both StaffLines)
- if (!musicSystem.checkStaffEntriesForStaffEntryLink()) {
- for (let i: number = 0; i < musicSystem.StaffLines.length - 1; i++) {
- const upperBottomLine: number = musicSystem.StaffLines[i].SkyBottomLineCalculator.getBottomLineMax();
- // TODO: Lower skyline should add to offset when there are items above the line. Currently no test
- // file available
- // const lowerSkyLine: number = Math.min(...musicSystem.StaffLines[i + 1].SkyLine);
- if (Math.abs(upperBottomLine) > this.rules.MinimumStaffLineDistance) {
- // Remove staffheight from offset. As it results in huge distances
- const offset: number = Math.abs(upperBottomLine) + this.rules.MinimumStaffLineDistance - this.rules.StaffHeight;
- this.updateStaffLinesRelativePosition(musicSystem, i + 1, offset);
- }
- }
- }
- }
- /**
- * This method updates the System's StaffLine's RelativePosition (starting from the given index).
- * @param musicSystem
- * @param index
- * @param value
- */
- protected updateStaffLinesRelativePosition(musicSystem: MusicSystem, index: number, value: number): void {
- for (let i: number = index; i < musicSystem.StaffLines.length; i++) {
- musicSystem.StaffLines[i].PositionAndShape.RelativePosition.y += value;
- }
- musicSystem.PositionAndShape.BorderBottom += value;
- }
- protected calculateSystemYLayout(): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Called for every source measure when generating the list of staff measures for it.
- */
- protected initGraphicalMeasuresCreation(): void {
- throw new Error("abstract, not implemented");
- }
- protected handleBeam(graphicalNote: GraphicalNote, beam: Beam, openBeams: Beam[]): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Check if the tied graphical note belongs to any beams or tuplets and react accordingly.
- * @param tiedGraphicalNote
- * @param beams
- * @param activeClef
- * @param octaveShiftValue
- * @param graphicalStaffEntry
- * @param duration
- * @param openTie
- * @param isLastTieNote
- */
- protected handleTiedGraphicalNote(tiedGraphicalNote: GraphicalNote, beams: Beam[], activeClef: ClefInstruction,
- octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction,
- openTie: Tie, isLastTieNote: boolean): void {
- throw new Error("abstract, not implemented");
- }
- protected handleVoiceEntryLyrics(voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry,
- openLyricWords: LyricWord[]): void {
- throw new Error("abstract, not implemented");
- }
- protected handleVoiceEntryOrnaments(ornamentContainer: OrnamentContainer, voiceEntry: VoiceEntry,
- graphicalStaffEntry: GraphicalStaffEntry): void {
- throw new Error("abstract, not implemented");
- }
- protected handleVoiceEntryArticulations(articulations: ArticulationEnum[],
- voiceEntry: VoiceEntry,
- staffEntry: GraphicalStaffEntry): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Adds a technical instruction at the given staff entry.
- * @param technicalInstructions
- * @param voiceEntry
- * @param staffEntry
- */
- protected handleVoiceEntryTechnicalInstructions(technicalInstructions: TechnicalInstruction[],
- voiceEntry: VoiceEntry, staffEntry: GraphicalStaffEntry): void {
- throw new Error("abstract, not implemented");
- }
- protected handleTuplet(graphicalNote: GraphicalNote, tuplet: Tuplet, openTuplets: Tuplet[]): void {
- throw new Error("abstract, not implemented");
- }
- protected layoutVoiceEntry(voiceEntry: VoiceEntry, graphicalNotes: GraphicalNote[],
- graphicalStaffEntry: GraphicalStaffEntry, hasPitchedNote: boolean): void {
- throw new Error("abstract, not implemented");
- }
- protected layoutStaffEntry(graphicalStaffEntry: GraphicalStaffEntry): void {
- throw new Error("abstract, not implemented");
- }
- protected createGraphicalTie(tie: Tie, startGse: GraphicalStaffEntry, endGse: GraphicalStaffEntry, startNote: GraphicalNote,
- endNote: GraphicalNote): GraphicalTie {
- throw new Error("abstract, not implemented");
- }
- protected updateStaffLineBorders(staffLine: StaffLine): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Iterate through all Measures and calculates the MeasureNumberLabels.
- * @param musicSystem
- */
- protected calculateMeasureNumberPlacement(musicSystem: MusicSystem): void {
- const staffLine: StaffLine = musicSystem.StaffLines[0];
- let currentMeasureNumber: number = staffLine.Measures[0].MeasureNumber;
- for (const measure of staffLine.Measures) {
- if (measure.MeasureNumber === 0 || measure.MeasureNumber === 1) {
- currentMeasureNumber = measure.MeasureNumber;
- }
- if ((measure.MeasureNumber === currentMeasureNumber ||
- measure.MeasureNumber === currentMeasureNumber + this.rules.MeasureNumberLabelOffset) &&
- !measure.parentSourceMeasure.ImplicitMeasure) {
- if (measure.MeasureNumber !== 1 ||
- (measure.MeasureNumber === 1 && measure !== staffLine.Measures[0])) {
- this.calculateSingleMeasureNumberPlacement(measure, staffLine, musicSystem);
- }
- currentMeasureNumber = measure.MeasureNumber;
- }
- }
- }
- /// <summary>
- /// This method calculates a single MeasureNumberLabel and adds it to the graphical label list of the music system
- /// </summary>
- /// <param name="measure"></param>
- /// <param name="staffLine"></param>
- /// <param name="musicSystem"></param>
- private calculateSingleMeasureNumberPlacement(measure: GraphicalMeasure, staffLine: StaffLine, musicSystem: MusicSystem): void {
- const labelNumber: string = measure.MeasureNumber.toString();
- const graphicalLabel: GraphicalLabel = new GraphicalLabel(new Label(labelNumber), this.rules.MeasureNumberLabelHeight,
- TextAlignmentEnum.LeftBottom);
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- // calculate LabelBoundingBox and set PSI parent
- graphicalLabel.setLabelPositionAndShapeBorders();
- graphicalLabel.PositionAndShape.Parent = musicSystem.PositionAndShape;
- // calculate relative Position
- const relativeX: number = staffLine.PositionAndShape.RelativePosition.x +
- measure.PositionAndShape.RelativePosition.x - graphicalLabel.PositionAndShape.BorderMarginLeft;
- let relativeY: number;
- // and the corresponding SkyLine indices
- let start: number = relativeX;
- let end: number = relativeX - graphicalLabel.PositionAndShape.BorderLeft + graphicalLabel.PositionAndShape.BorderMarginRight;
- // take into account the InstrumentNameLabel's at the beginning of the first MusicSystem
- if (staffLine === musicSystem.StaffLines[0] && musicSystem === musicSystem.Parent.MusicSystems[0]) {
- start -= staffLine.PositionAndShape.RelativePosition.x;
- end -= staffLine.PositionAndShape.RelativePosition.x;
- }
- // get the minimum corresponding SkyLine value
- const skyLineMinValue: number = skyBottomLineCalculator.getSkyLineMinInRange(start, end);
- if (measure === staffLine.Measures[0]) {
- // must take into account possible MusicSystem Bracket's
- let minBracketTopBorder: number = 0;
- if (musicSystem.GroupBrackets.length > 0) {
- for (const groupBracket of musicSystem.GroupBrackets) {
- minBracketTopBorder = Math.min(minBracketTopBorder, groupBracket.PositionAndShape.BorderTop);
- }
- }
- relativeY = Math.min(skyLineMinValue, minBracketTopBorder);
- } else {
- relativeY = skyLineMinValue;
- }
- relativeY = Math.min(0, relativeY);
- graphicalLabel.PositionAndShape.RelativePosition = new PointF2D(relativeX, relativeY);
- skyBottomLineCalculator.updateSkyLineInRange(start, end, relativeY + graphicalLabel.PositionAndShape.BorderMarginTop);
- musicSystem.MeasureNumberLabels.push(graphicalLabel);
- }
- /**
- * Calculate the shape (Bézier curve) for this tie.
- * @param tie
- * @param tieIsAtSystemBreak
- */
- protected layoutGraphicalTie(tie: GraphicalTie, tieIsAtSystemBreak: boolean): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Calculate the Lyrics YPositions for a single [[StaffLine]].
- * @param staffLine
- * @param lyricVersesNumber
- */
- protected calculateSingleStaffLineLyricsPosition(staffLine: StaffLine, lyricVersesNumber: number[]): GraphicalStaffEntry[] {
- let numberOfVerses: number = 0;
- let lyricsStartYPosition: number = this.rules.StaffHeight; // Add offset to prevent collision
- const lyricsStaffEntriesList: GraphicalStaffEntry[] = [];
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- // first find maximum Ycoordinate for the whole StaffLine
- let len: number = staffLine.Measures.length;
- for (let idx: number = 0; idx < len; ++idx) {
- const measure: GraphicalMeasure = staffLine.Measures[idx];
- const measureRelativePosition: PointF2D = measure.PositionAndShape.RelativePosition;
- const len2: number = measure.staffEntries.length;
- for (let idx2: number = 0; idx2 < len2; ++idx2) {
- const staffEntry: GraphicalStaffEntry = measure.staffEntries[idx2];
- if (staffEntry.LyricsEntries.length > 0) {
- lyricsStaffEntriesList.push(staffEntry);
- numberOfVerses = Math.max(numberOfVerses, staffEntry.LyricsEntries.length);
- // Position of Staffentry relative to StaffLine
- const staffEntryPositionX: number = staffEntry.PositionAndShape.RelativePosition.x +
- measureRelativePosition.x;
- let minMarginLeft: number = Number.MAX_VALUE;
- let maxMarginRight: number = Number.MIN_VALUE;
- // if more than one LyricEntry in StaffEntry, find minMarginLeft, maxMarginRight of all corresponding Labels
- for (let i: number = 0; i < staffEntry.LyricsEntries.length; i++) {
- const lyricsEntryLabel: GraphicalLabel = staffEntry.LyricsEntries[i].GraphicalLabel;
- minMarginLeft = Math.min(minMarginLeft, staffEntryPositionX + lyricsEntryLabel.PositionAndShape.BorderMarginLeft);
- maxMarginRight = Math.max(maxMarginRight, staffEntryPositionX + lyricsEntryLabel.PositionAndShape.BorderMarginRight);
- }
- // check BottomLine in this range and take the maximum between the two values
- const bottomLineMax: number = skyBottomLineCalculator.getBottomLineMaxInRange(minMarginLeft, maxMarginRight);
- lyricsStartYPosition = Math.max(lyricsStartYPosition, bottomLineMax);
- }
- }
- }
- let maxPosition: number = 0;
- // iterate again through the Staffentries with LyricEntries
- len = lyricsStaffEntriesList.length;
- for (const staffEntry of lyricsStaffEntriesList) {
- // set LyricEntryLabel RelativePosition
- for (let i: number = 0; i < staffEntry.LyricsEntries.length; i++) {
- const lyricEntry: GraphicalLyricEntry = staffEntry.LyricsEntries[i];
- const lyricsEntryLabel: GraphicalLabel = lyricEntry.GraphicalLabel;
- // read the verseNumber and get index of this number in the sorted LyricVerseNumbersList of Instrument
- // eg verseNumbers: 2,3,4,6 => 1,2,3,4
- const verseNumber: number = lyricEntry.LyricsEntry.VerseNumber;
- const sortedLyricVerseNumberIndex: number = lyricVersesNumber.indexOf(verseNumber);
- const firstPosition: number = lyricsStartYPosition + this.rules.LyricsHeight + this.rules.VerticalBetweenLyricsDistance;
- // Y-position calculated according to aforementioned mapping
- let position: number = firstPosition + (this.rules.VerticalBetweenLyricsDistance + this.rules.LyricsHeight) * sortedLyricVerseNumberIndex;
- if (this.leadSheet) {
- position = 3.4 + (this.rules.VerticalBetweenLyricsDistance + this.rules.LyricsHeight) * (sortedLyricVerseNumberIndex);
- }
- const previousRelativeX: number = lyricsEntryLabel.PositionAndShape.RelativePosition.x;
- lyricsEntryLabel.PositionAndShape.RelativePosition = new PointF2D(previousRelativeX, position);
- maxPosition = Math.max(maxPosition, position);
- }
- }
- // update BottomLine (on the whole StaffLine's length)
- if (lyricsStaffEntriesList.length > 0) {
- const endX: number = staffLine.PositionAndShape.Size.width;
- let startX: number = lyricsStaffEntriesList[0].PositionAndShape.RelativePosition.x +
- lyricsStaffEntriesList[0].PositionAndShape.BorderMarginLeft +
- lyricsStaffEntriesList[0].parentMeasure.PositionAndShape.RelativePosition.x;
- startX = startX > endX ? endX : startX;
- skyBottomLineCalculator.updateBottomLineInRange(startX, endX, maxPosition);
- }
- return lyricsStaffEntriesList;
- }
- /**
- * calculates the dashes of lyric words and the extending underscore lines of syllables sung on more than one note.
- * @param lyricsStaffEntries
- */
- protected calculateLyricsExtendsAndDashes(lyricsStaffEntries: GraphicalStaffEntry[]): void {
- // iterate again to create now the extend lines and dashes for words
- for (let idx: number = 0, len: number = lyricsStaffEntries.length; idx < len; ++idx) {
- const staffEntry: GraphicalStaffEntry = lyricsStaffEntries[idx];
- // set LyricEntryLabel RelativePosition
- for (let i: number = 0; i < staffEntry.LyricsEntries.length; i++) {
- const lyricEntry: GraphicalLyricEntry = staffEntry.LyricsEntries[i];
- // calculate LyricWord's Dashes and underscoreLine
- if (lyricEntry.ParentLyricWord !== undefined &&
- lyricEntry.ParentLyricWord.GraphicalLyricsEntries[lyricEntry.ParentLyricWord.GraphicalLyricsEntries.length - 1] !== lyricEntry) {
- this.calculateSingleLyricWord(lyricEntry);
- }
- // calculate the underscore line extend if needed
- if (lyricEntry.LyricsEntry.extend) {
- this.calculateLyricExtend(lyricEntry);
- }
- }
- }
- }
- /**
- * Calculate a single OctaveShift for a [[MultiExpression]].
- * @param sourceMeasure
- * @param multiExpression
- * @param measureIndex
- * @param staffIndex
- */
- protected calculateSingleOctaveShift(sourceMeasure: SourceMeasure, multiExpression: MultiExpression,
- measureIndex: number, staffIndex: number): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Calculate all the textual [[RepetitionInstruction]]s (e.g. dal segno) for a single [[SourceMeasure]].
- * @param repetitionInstruction
- * @param measureIndex
- */
- protected calculateWordRepetitionInstruction(repetitionInstruction: RepetitionInstruction,
- measureIndex: number): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Calculate all the Mood and Unknown Expressions for a single [[MultiExpression]].
- * @param multiExpression
- * @param measureIndex
- * @param staffIndex
- */
- protected calculateMoodAndUnknownExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
- throw new Error("abstract, not implemented");
- }
- /**
- * Delete all Objects that must be recalculated.
- * If graphicalMusicSheet.reCalculate has been called, then this method will be called to reset or remove all flexible
- * graphical music symbols (e.g. Ornaments, Lyrics, Slurs) graphicalMusicSheet will have MusicPages, they will have MusicSystems etc...
- */
- protected clearRecreatedObjects(): void {
- // Clear StaffEntries with GraphicalTies
- for (let idx: number = 0, len: number = this.staffEntriesWithGraphicalTies.length; idx < len; ++idx) {
- const staffEntriesWithGraphicalTie: GraphicalStaffEntry = this.staffEntriesWithGraphicalTies[idx];
- staffEntriesWithGraphicalTie.GraphicalTies.length = 0;
- }
- this.staffEntriesWithGraphicalTies.length = 0;
- return;
- }
- /**
- * This method handles a [[StaffEntryLink]].
- * @param graphicalStaffEntry
- * @param staffEntryLinks
- */
- protected handleStaffEntryLink(graphicalStaffEntry: GraphicalStaffEntry,
- staffEntryLinks: StaffEntryLink[]): void {
- log.debug("handleStaffEntryLink not implemented");
- }
- /**
- * Store the newly computed [[Measure]]s in newly created [[MusicSystem]]s.
- */
- protected calculateMusicSystems(): void {
- if (this.graphicalMusicSheet.MeasureList === undefined) {
- return;
- }
- const allMeasures: GraphicalMeasure[][] = this.graphicalMusicSheet.MeasureList;
- if (allMeasures === undefined) {
- return;
- }
- // visible 2D-MeasureList
- const visibleMeasureList: GraphicalMeasure[][] = [];
- for (let idx: number = 0, len: number = allMeasures.length; idx < len; ++idx) {
- const graphicalMeasures: GraphicalMeasure[] = allMeasures[idx];
- const visiblegraphicalMeasures: GraphicalMeasure[] = [];
- for (let idx2: number = 0, len2: number = graphicalMeasures.length; idx2 < len2; ++idx2) {
- const graphicalMeasure: GraphicalMeasure = allMeasures[idx][idx2];
- if (graphicalMeasure.isVisible()) {
- visiblegraphicalMeasures.push(graphicalMeasure);
- }
- }
- visibleMeasureList.push(visiblegraphicalMeasures);
- }
- // find out how many StaffLine Instances we need
- let numberOfStaffLines: number = 0;
- for (let idx: number = 0, len: number = visibleMeasureList.length; idx < len; ++idx) {
- const gmlist: GraphicalMeasure[] = visibleMeasureList[idx];
- numberOfStaffLines = Math.max(gmlist.length, numberOfStaffLines);
- break;
- }
- if (numberOfStaffLines === 0) {
- return;
- }
- // build the MusicSystems
- const musicSystemBuilder: MusicSystemBuilder = new MusicSystemBuilder();
- musicSystemBuilder.initialize(this.graphicalMusicSheet, visibleMeasureList, numberOfStaffLines);
- musicSystemBuilder.buildMusicSystems();
- this.formatMeasures();
- // check for Measures with only WholeRestNotes and correct their X-Position (middle of Measure)
- this.checkMeasuresForWholeRestNotes();
- if (!this.leadSheet) {
- // calculate Beam Placement
- this.calculateBeams();
- // possible Displacement of RestNotes
- this.optimizeRestPlacement();
- // possible Displacement of RestNotes
- this.calculateStaffEntryArticulationMarks();
- // calculate Ties
- this.calculateTieCurves();
- }
- // calculate Sky- and BottomLine
- // will have reasonable values only between ObjectsBorders (eg StaffEntries)
- this.calculateSkyBottomLines();
- // calculate TupletsNumbers
- this.calculateTupletNumbers();
- // calculate MeasureNumbers
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- this.calculateMeasureNumberPlacement(musicSystem);
- }
- }
- // calculate Slurs
- if (!this.leadSheet) {
- this.calculateSlurs();
- }
- // calculate StaffEntry Ornaments
- // (must come after Slurs)
- if (!this.leadSheet) {
- this.calculateOrnaments();
- }
- // calculate StaffEntry ChordSymbols
- this.calculateChordSymbols();
- if (!this.leadSheet) {
- // calculate all Instantaneous/Continuous Dynamics Expressions
- this.calculateDynamicExpressions();
- // calculate all Mood and Unknown Expression
- this.calculateMoodAndUnknownExpressions();
- // Calculate the alignment of close expressions
- this.calculateExpressionAlignements();
- // calculate all OctaveShifts
- this.calculateOctaveShifts();
- // calcualte RepetitionInstructions (Dal Segno, Coda, etc)
- this.calculateWordRepetitionInstructions();
- }
- // calculate endings last, so they appear above measure numbers
- this.calculateRepetitionEndings();
- // calcualte all Tempo Expressions
- if (!this.leadSheet) {
- this.calculateTempoExpressions();
- }
- // calculate all LyricWords Positions
- this.calculateLyricsPosition();
- // update all StaffLine's Borders
- // create temporary Object, just to call the methods (in order to avoid declaring them static)
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- this.updateStaffLineBorders(staffLine);
- }
- }
- }
- // Y-spacing
- this.calculateSystemYLayout();
- // calculate Comments for each Staffline
- this.calculateComments();
- // calculate marked Areas for Systems
- this.calculateMarkedAreas();
- // the following must be done after Y-spacing, when the MusicSystems's final Dimensions are set
- // set the final yPositions of Objects such as SystemLabels and SystemLinesContainers,
- // create all System Lines, Brackets and MeasureNumbers (for all systems and for all pages)
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- musicSystem.setMusicSystemLabelsYPosition();
- if (!this.leadSheet) {
- musicSystem.setYPositionsToVerticalLineObjectsAndCreateLines(this.rules);
- musicSystem.createSystemLeftLine(this.rules.SystemThinLineWidth, this.rules.SystemLabelsRightMargin);
- musicSystem.createInstrumentBrackets(this.graphicalMusicSheet.ParentMusicSheet.Instruments, this.rules.StaffHeight);
- musicSystem.createGroupBrackets(this.graphicalMusicSheet.ParentMusicSheet.InstrumentalGroups, this.rules.StaffHeight, 0);
- musicSystem.alignBeginInstructions();
- } else if (musicSystem === musicSystem.Parent.MusicSystems[0]) {
- musicSystem.createSystemLeftLine(this.rules.SystemThinLineWidth, this.rules.SystemLabelsRightMargin);
- }
- musicSystem.calculateBorders(this.rules);
- }
- const distance: number = graphicalMusicPage.MusicSystems[0].PositionAndShape.BorderTop;
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- // let newPosition: PointF2D = new PointF2D(musicSystem.PositionAndShape.RelativePosition.x,
- // musicSystem.PositionAndShape.RelativePosition.y - distance);
- musicSystem.PositionAndShape.RelativePosition =
- new PointF2D(musicSystem.PositionAndShape.RelativePosition.x, musicSystem.PositionAndShape.RelativePosition.y - distance);
- }
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- staffLine.addActivitySymbolClickArea();
- }
- }
- // calculate all Labels's Positions for the first Page
- if (graphicalMusicPage === this.graphicalMusicSheet.MusicPages[0]) {
- this.calculatePageLabels(graphicalMusicPage);
- }
- // calculate TopBottom Borders for all elements recursively
- graphicalMusicPage.PositionAndShape.calculateTopBottomBorders();
- }
- }
- protected calculateMarkedAreas(): void {
- //log.debug("calculateMarkedAreas not implemented");
- return;
- }
- protected calculateComments(): void {
- //log.debug("calculateComments not implemented");
- return;
- }
- protected calculateChordSymbols(): void {
- return;
- }
- /**
- * Do layout on staff measures which only consist of a full rest.
- * @param rest
- * @param gse
- * @param measure
- */
- protected layoutMeasureWithWholeRest(rest: GraphicalNote, gse: GraphicalStaffEntry,
- measure: GraphicalMeasure): void {
- return;
- }
- protected layoutBeams(staffEntry: GraphicalStaffEntry): void {
- return;
- }
- protected layoutArticulationMarks(articulations: ArticulationEnum[], voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry): void {
- return;
- }
- protected layoutOrnament(ornaments: OrnamentContainer, voiceEntry: VoiceEntry,
- graphicalStaffEntry: GraphicalStaffEntry): void {
- return;
- }
- protected calculateRestNotePlacementWithinGraphicalBeam(graphicalStaffEntry: GraphicalStaffEntry,
- restNote: GraphicalNote,
- previousNote: GraphicalNote,
- nextStaffEntry: GraphicalStaffEntry,
- nextNote: GraphicalNote): void {
- return;
- }
- protected calculateTupletNumbers(): void {
- return;
- }
- protected calculateSlurs(): void {
- return;
- }
- protected calculateDynamicExpressionsForMultiExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
- return;
- }
- /**
- * This method calculates the RelativePosition of a single verbal GraphicalContinuousDynamic.
- * @param graphicalContinuousDynamic Graphical continous dynamic to be calculated
- * @param startPosInStaffline Starting point in staff line
- */
- protected calculateGraphicalVerbalContinuousDynamic(graphicalContinuousDynamic: GraphicalContinuousDynamicExpression,
- startPosInStaffline: PointF2D): void {
- // if ContinuousDynamicExpression is given from words
- const graphLabel: GraphicalLabel = graphicalContinuousDynamic.Label;
- const left: number = startPosInStaffline.x + graphLabel.PositionAndShape.BorderMarginLeft;
- const right: number = startPosInStaffline.x + graphLabel.PositionAndShape.BorderMarginRight;
- // placement always below the currentStaffLine, with the exception of Voice Instrument (-> above)
- const placement: PlacementEnum = graphicalContinuousDynamic.ContinuousDynamic.Placement;
- const staffLine: StaffLine = graphicalContinuousDynamic.ParentStaffLine;
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- let drawingHeight: number;
- if (placement === PlacementEnum.Below) {
- drawingHeight = skyBottomLineCalculator.getBottomLineMaxInRange(left, right); // Bottom line
- graphLabel.PositionAndShape.RelativePosition = new PointF2D(startPosInStaffline.x, drawingHeight - graphLabel.PositionAndShape.BorderMarginTop);
- } else {
- drawingHeight = skyBottomLineCalculator.getSkyLineMinInRange(left, right);
- graphLabel.PositionAndShape.RelativePosition = new PointF2D(startPosInStaffline.x, drawingHeight - graphLabel.PositionAndShape.BorderMarginBottom);
- }
- }
- /**
- * This method calculates the RelativePosition of a single GraphicalContinuousDynamic.
- * @param graphicalContinuousDynamic Graphical continous dynamic to be calculated
- * @param startPosInStaffline Starting point in staff line
- */
- public calculateGraphicalContinuousDynamic(graphicalContinuousDynamic: GraphicalContinuousDynamicExpression, startPosInStaffline: PointF2D): void {
- const staffIndex: number = graphicalContinuousDynamic.ParentStaffLine.ParentStaff.idInMusicSheet;
- // TODO: Previously the staffIndex was passed down. BUT you can (and this function actually does this) get it from
- // the musicSystem OR from the ParentStaffLine. Is this the same index?
- // const staffIndex: number = musicSystem.StaffLines.indexOf(staffLine);
- // We know we have an end measure because otherwise we won't be called
- const endMeasure: GraphicalMeasure = this.graphicalMusicSheet.getGraphicalMeasureFromSourceMeasureAndIndex(
- graphicalContinuousDynamic.ContinuousDynamic.EndMultiExpression.SourceMeasureParent, staffIndex);
- if (!endMeasure) {
- log.warn("Not working");
- return;
- }
- graphicalContinuousDynamic.EndMeasure = endMeasure;
- const endStaffLine: StaffLine = endMeasure.ParentStaffLine;
- const endAbsoluteTimestamp: Fraction = Fraction.createFromFraction(graphicalContinuousDynamic.ContinuousDynamic.EndMultiExpression.AbsoluteTimestamp);
- const endPosInStaffLine: PointF2D = this.getRelativePositionInStaffLineFromTimestamp(
- endAbsoluteTimestamp, staffIndex, endStaffLine, endStaffLine.isPartOfMultiStaffInstrument(), 0);
- const staffLine: StaffLine = graphicalContinuousDynamic.ParentStaffLine;
- //currentMusicSystem and currentStaffLine
- const musicSystem: MusicSystem = staffLine.ParentMusicSystem;
- const currentStaffLineIndex: number = musicSystem.StaffLines.indexOf(staffLine);
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- // let expressionIndex: number;
- // placement always below the currentStaffLine, with the exception of Voice Instrument (-> above)
- const placement: PlacementEnum = graphicalContinuousDynamic.ContinuousDynamic.Placement;
- // if ContinuousDynamicExpression is given from wedge
- let secondGraphicalContinuousDynamic: GraphicalContinuousDynamicExpression = undefined;
- // check if Expression spreads over the same StaffLine or not
- const sameStaffLine: boolean = endStaffLine !== undefined && staffLine === endStaffLine;
- // last length check
- if (sameStaffLine && endPosInStaffLine.x - startPosInStaffline.x < this.rules.WedgeMinLength) {
- endPosInStaffLine.x = startPosInStaffline.x + this.rules.WedgeMinLength;
- }
- // Upper staff wedge always starts at the given position and the lower staff wedge always starts at the begin of measure
- const upperStartX: number = startPosInStaffline.x;
- const lowerStartX: number = endStaffLine.Measures[0].beginInstructionsWidth - this.rules.WedgeHorizontalMargin - 2;
- let upperEndX: number = 0;
- let lowerEndX: number = 0;
- if (!sameStaffLine) {
- upperEndX = staffLine.PositionAndShape.Size.width;
- lowerEndX = endPosInStaffLine.x;
- // must create a new Wedge
- secondGraphicalContinuousDynamic = new GraphicalContinuousDynamicExpression(graphicalContinuousDynamic.ContinuousDynamic, endStaffLine);
- secondGraphicalContinuousDynamic.IsSplittedPart = true;
- graphicalContinuousDynamic.IsSplittedPart = true;
- } else {
- upperEndX = endPosInStaffLine.x;
- }
- // the Height of the Expression's placement
- let idealY: number = 0;
- let secondIdealY: number = 0;
- if (placement === PlacementEnum.Below) {
- // can be a single Staff Instrument or an Instrument with 2 Staves
- let nextStaffLineIndex: number = 0;
- if (currentStaffLineIndex < musicSystem.StaffLines.length - 1) {
- nextStaffLineIndex = currentStaffLineIndex + 1;
- }
- // check, maybe currentStaffLine is the last of the MusicSystem (and it has a ContinuousDynamicExpression with placement below)
- if (nextStaffLineIndex > currentStaffLineIndex) {
- // currentStaffLine isn't the last of the MusicSystem
- const nextStaffLine: StaffLine = musicSystem.StaffLines[nextStaffLineIndex];
- const distanceBetweenStaffLines: number = nextStaffLine.PositionAndShape.RelativePosition.y -
- staffLine.PositionAndShape.RelativePosition.y -
- this.rules.StaffHeight;
- // ideal Height is exactly between the two StaffLines
- idealY = this.rules.StaffHeight + distanceBetweenStaffLines / 2;
- } else {
- // currentStaffLine is the MusicSystem's last
- idealY = this.rules.WedgePlacementBelowY;
- }
- // must consider the upperWedge starting/ending tip for the comparison with the BottomLine
- idealY -= this.rules.WedgeOpeningLength / 2;
- if (!sameStaffLine) {
- // Set the value for the splitted y position to the ideal position before we check and modify it with
- // the skybottom calculator detection
- secondIdealY = idealY;
- }
- // must check BottomLine for possible collisions within the Length of the Expression
- // find the corresponding max value for the given Length
- let maxBottomLineValueForExpressionLength: number = skyBottomLineCalculator.getBottomLineMaxInRange(upperStartX, upperEndX);
- // if collisions, then set the Height accordingly
- if (maxBottomLineValueForExpressionLength > idealY) {
- idealY = maxBottomLineValueForExpressionLength;
- }
- // special case - wedge must be drawn within the boundaries of a crossedBeam
- const withinCrossedBeam: boolean = false;
- if (currentStaffLineIndex < musicSystem.StaffLines.length - 1) {
- // find GraphicalStaffEntries closest to wedge's xPositions
- const closestToEndStaffEntry: GraphicalStaffEntry = staffLine.findClosestStaffEntry(upperEndX);
- const closestToStartStaffEntry: GraphicalStaffEntry = staffLine.findClosestStaffEntry(upperStartX);
- if (closestToStartStaffEntry && closestToEndStaffEntry) {
- // must check both StaffLines
- const startVerticalContainer: VerticalGraphicalStaffEntryContainer = closestToStartStaffEntry.parentVerticalContainer;
- // const endVerticalContainer: VerticalGraphicalStaffEntryContainer = closestToEndStaffEntry.parentVerticalContainer;
- if (startVerticalContainer) {
- // TODO: Needs to be implemented?
- // withinCrossedBeam = areStaffEntriesWithinCrossedBeam(startVerticalContainer,
- // endVerticalContainer, currentStaffLineIndex, nextStaffLineIndex);
- }
- if (withinCrossedBeam) {
- const nextStaffLine: StaffLine = musicSystem.StaffLines[nextStaffLineIndex];
- const nextStaffLineMinSkyLineValue: number = nextStaffLine.SkyBottomLineCalculator.getSkyLineMinInRange(upperStartX, upperEndX);
- const distanceBetweenStaffLines: number = nextStaffLine.PositionAndShape.RelativePosition.y -
- staffLine.PositionAndShape.RelativePosition.y;
- const relativeSkyLineHeight: number = distanceBetweenStaffLines + nextStaffLineMinSkyLineValue;
- if (relativeSkyLineHeight - this.rules.WedgeOpeningLength > this.rules.StaffHeight) {
- idealY = relativeSkyLineHeight - this.rules.WedgeVerticalMargin;
- } else {
- idealY = this.rules.StaffHeight + this.rules.WedgeOpeningLength;
- }
- graphicalContinuousDynamic.NotToBeRemoved = true;
- }
- }
- }
- // do the same in case of a Wedge ending at another StaffLine
- if (!sameStaffLine) {
- maxBottomLineValueForExpressionLength = endStaffLine.SkyBottomLineCalculator.getBottomLineMaxInRange(lowerStartX, lowerEndX);
- if (maxBottomLineValueForExpressionLength > secondIdealY) {
- secondIdealY = maxBottomLineValueForExpressionLength;
- }
- secondIdealY += this.rules.WedgeOpeningLength / 2;
- secondIdealY += this.rules.WedgeVerticalMargin;
- }
- if (!withinCrossedBeam) {
- idealY += this.rules.WedgeOpeningLength / 2;
- idealY += this.rules.WedgeVerticalMargin;
- }
- } else if (placement === PlacementEnum.Above) {
- // single Staff Instrument (eg Voice)
- if (staffLine.ParentStaff.ParentInstrument.Staves.length === 1) {
- // single Staff Voice Instrument
- idealY = this.rules.WedgePlacementAboveY;
- } else {
- // Staff = not the first Staff of a 2-staved Instrument
- let previousStaffLineIndex: number = 0;
- if (currentStaffLineIndex > 0) {
- previousStaffLineIndex = currentStaffLineIndex - 1;
- }
- const previousStaffLine: StaffLine = musicSystem.StaffLines[previousStaffLineIndex];
- const distanceBetweenStaffLines: number = staffLine.PositionAndShape.RelativePosition.y -
- previousStaffLine.PositionAndShape.RelativePosition.y -
- this.rules.StaffHeight;
- // ideal Height is exactly between the two StaffLines
- idealY = -distanceBetweenStaffLines / 2;
- }
- // must consider the upperWedge starting/ending tip for the comparison with the SkyLine
- idealY += this.rules.WedgeOpeningLength / 2;
- if (!sameStaffLine) {
- secondIdealY = idealY;
- }
- // must check SkyLine for possible collisions within the Length of the Expression
- // find the corresponding min value for the given Length
- let minSkyLineValueForExpressionLength: number = skyBottomLineCalculator.getSkyLineMinInRange(upperStartX, upperEndX);
- // if collisions, then set the Height accordingly
- if (minSkyLineValueForExpressionLength < idealY) {
- idealY = minSkyLineValueForExpressionLength;
- }
- const withinCrossedBeam: boolean = false;
- // special case - wedge must be drawn within the boundaries of a crossedBeam
- if (staffLine.ParentStaff.ParentInstrument.Staves.length > 1 && currentStaffLineIndex > 0) {
- // find GraphicalStaffEntries closest to wedge's xPositions
- const closestToStartStaffEntry: GraphicalStaffEntry = staffLine.findClosestStaffEntry(upperStartX);
- const closestToEndStaffEntry: GraphicalStaffEntry = staffLine.findClosestStaffEntry(upperEndX);
- if (closestToStartStaffEntry && closestToEndStaffEntry) {
- // must check both StaffLines
- const startVerticalContainer: VerticalGraphicalStaffEntryContainer = closestToStartStaffEntry.parentVerticalContainer;
- // const endVerticalContainer: VerticalGraphicalStaffEntryContainer = closestToEndStaffEntry.parentVerticalContainer;
- const formerStaffLineIndex: number = currentStaffLineIndex - 1;
- if (startVerticalContainer) {
- // withinCrossedBeam = this.areStaffEntriesWithinCrossedBeam(startVerticalContainer,
- // endVerticalContainer, currentStaffLineIndex, formerStaffLineIndex);
- }
- if (withinCrossedBeam) {
- const formerStaffLine: StaffLine = musicSystem.StaffLines[formerStaffLineIndex];
- const formerStaffLineMaxBottomLineValue: number = formerStaffLine.SkyBottomLineCalculator.
- getBottomLineMaxInRange(upperStartX, upperEndX);
- const distanceBetweenStaffLines: number = staffLine.PositionAndShape.RelativePosition.y -
- formerStaffLine.PositionAndShape.RelativePosition.y;
- const relativeSkyLineHeight: number = distanceBetweenStaffLines - formerStaffLineMaxBottomLineValue;
- idealY = (relativeSkyLineHeight - this.rules.StaffHeight) / 2 + this.rules.StaffHeight;
- }
- }
- }
- // do the same in case of a Wedge ending at another StaffLine
- if (!sameStaffLine) {
- minSkyLineValueForExpressionLength = endStaffLine.SkyBottomLineCalculator.getSkyLineMinInRange(lowerStartX, lowerEndX);
- if (minSkyLineValueForExpressionLength < secondIdealY) {
- secondIdealY = minSkyLineValueForExpressionLength;
- }
- secondIdealY -= this.rules.WedgeOpeningLength / 2;
- }
- if (!withinCrossedBeam) {
- idealY -= this.rules.WedgeOpeningLength / 2;
- idealY -= this.rules.WedgeVerticalMargin;
- }
- if (!sameStaffLine) {
- secondIdealY -= this.rules.WedgeVerticalMargin;
- }
- }
- // now we have the correct placement Height for the Expression
- // the idealY is calculated relative to the currentStaffLine
- // Crescendo (point to the left, opening to the right)
- graphicalContinuousDynamic.Lines.clear();
- if (graphicalContinuousDynamic.ContinuousDynamic.DynamicType === ContDynamicEnum.crescendo) {
- if (sameStaffLine) {
- graphicalContinuousDynamic.createCrescendoLines(upperStartX, upperEndX, idealY);
- graphicalContinuousDynamic.calcPsi();
- } else {
- // two different Wedges
- graphicalContinuousDynamic.createFirstHalfCrescendoLines(upperStartX, upperEndX, idealY);
- graphicalContinuousDynamic.calcPsi();
- secondGraphicalContinuousDynamic.createSecondHalfCrescendoLines(lowerStartX, lowerEndX, secondIdealY);
- secondGraphicalContinuousDynamic.calcPsi();
- }
- } else if (graphicalContinuousDynamic.ContinuousDynamic.DynamicType === ContDynamicEnum.diminuendo) {
- if (sameStaffLine) {
- graphicalContinuousDynamic.createDiminuendoLines(upperStartX, upperEndX, idealY);
- graphicalContinuousDynamic.calcPsi();
- } else {
- graphicalContinuousDynamic.createFirstHalfDiminuendoLines(upperStartX, upperEndX, idealY);
- graphicalContinuousDynamic.calcPsi();
- secondGraphicalContinuousDynamic.createSecondHalfDiminuendoLines(lowerStartX, lowerEndX, secondIdealY);
- secondGraphicalContinuousDynamic.calcPsi();
- }
- } //End Diminuendo
- }
- /**
- * This method calculates the RelativePosition of a single GraphicalInstantaneousDynamicExpression.
- * @param graphicalInstantaneousDynamic Dynamic expression to be calculated
- * @param startPosInStaffline Starting point in staff line
- */
- protected calculateGraphicalInstantaneousDynamicExpression(graphicalInstantaneousDynamic: GraphicalInstantaneousDynamicExpression,
- startPosInStaffline: PointF2D): void {
- // get Margin Dimensions
- const staffLine: StaffLine = graphicalInstantaneousDynamic.ParentStaffLine;
- const left: number = startPosInStaffline.x + graphicalInstantaneousDynamic.PositionAndShape.BorderMarginLeft;
- const right: number = startPosInStaffline.x + graphicalInstantaneousDynamic.PositionAndShape.BorderMarginRight;
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- let yPosition: number = 0;
- // calculate yPosition according to Placement
- if (graphicalInstantaneousDynamic.Placement === PlacementEnum.Above) {
- const skyLineValue: number = skyBottomLineCalculator.getSkyLineMinInRange(left, right);
- // if StaffLine part of multiStaff Instrument and not the first one, ideal yPosition middle of distance between Staves
- if (staffLine.isPartOfMultiStaffInstrument() && staffLine.ParentStaff !== staffLine.ParentStaff.ParentInstrument.Staves[0]) {
- const formerStaffLine: StaffLine = staffLine.ParentMusicSystem.StaffLines[staffLine.ParentMusicSystem.StaffLines.indexOf(staffLine) - 1];
- const difference: number = staffLine.PositionAndShape.RelativePosition.y -
- formerStaffLine.PositionAndShape.RelativePosition.y - this.rules.StaffHeight;
- // take always into account the size of the Dynamic
- if (skyLineValue > -difference / 2) {
- yPosition = -difference / 2;
- } else {
- yPosition = skyLineValue - graphicalInstantaneousDynamic.PositionAndShape.BorderMarginBottom;
- }
- } else {
- yPosition = skyLineValue - graphicalInstantaneousDynamic.PositionAndShape.BorderMarginBottom;
- }
- graphicalInstantaneousDynamic.PositionAndShape.RelativePosition = new PointF2D(startPosInStaffline.x, yPosition);
- } else if (graphicalInstantaneousDynamic.Placement === PlacementEnum.Below) {
- const bottomLineValue: number = skyBottomLineCalculator.getBottomLineMaxInRange(left, right);
- // if StaffLine part of multiStaff Instrument and not the last one, ideal yPosition middle of distance between Staves
- const lastStaff: Staff = staffLine.ParentStaff.ParentInstrument.Staves[staffLine.ParentStaff.ParentInstrument.Staves.length - 1];
- if (staffLine.isPartOfMultiStaffInstrument() && staffLine.ParentStaff !== lastStaff) {
- const nextStaffLine: StaffLine = staffLine.ParentMusicSystem.StaffLines[staffLine.ParentMusicSystem.StaffLines.indexOf(staffLine) + 1];
- const difference: number = nextStaffLine.PositionAndShape.RelativePosition.y -
- staffLine.PositionAndShape.RelativePosition.y - this.rules.StaffHeight;
- const border: number = graphicalInstantaneousDynamic.PositionAndShape.BorderMarginBottom;
- // take always into account the size of the Dynamic
- if (bottomLineValue + border < this.rules.StaffHeight + difference / 2) {
- yPosition = this.rules.StaffHeight + difference / 2;
- } else {
- yPosition = bottomLineValue - graphicalInstantaneousDynamic.PositionAndShape.BorderMarginTop;
- }
- } else {
- yPosition = bottomLineValue - graphicalInstantaneousDynamic.PositionAndShape.BorderMarginTop;
- }
- graphicalInstantaneousDynamic.PositionAndShape.RelativePosition = new PointF2D(startPosInStaffline.x, yPosition);
- }
- graphicalInstantaneousDynamic.updateSkyBottomLine();
- }
- protected calcGraphicalRepetitionEndingsRecursively(repetition: Repetition): void {
- return;
- }
- /**
- * Calculate a single GraphicalRepetition.
- * @param start
- * @param end
- * @param numberText
- * @param offset
- * @param leftOpen
- * @param rightOpen
- */
- protected layoutSingleRepetitionEnding(start: GraphicalMeasure, end: GraphicalMeasure, numberText: string,
- offset: number, leftOpen: boolean, rightOpen: boolean): void {
- return;
- }
- protected calculateLabel(staffLine: StaffLine,
- relative: PointF2D,
- combinedString: string,
- style: FontStyles,
- placement: PlacementEnum,
- fontHeight: number,
- textAlignment: TextAlignmentEnum = TextAlignmentEnum.CenterBottom): GraphicalLabel {
- const label: Label = new Label(combinedString, textAlignment);
- label.fontHeight = fontHeight;
- // TODO_RR: TextHeight from first Entry
- const graphLabel: GraphicalLabel = new GraphicalLabel(label, fontHeight, label.textAlignment, staffLine.PositionAndShape);
- graphLabel.Label.fontStyle = style;
- const marginFactor: number = 1.1;
- if (placement === PlacementEnum.Below) {
- graphLabel.Label.textAlignment = TextAlignmentEnum.LeftTop;
- }
- graphLabel.setLabelPositionAndShapeBorders();
- graphLabel.PositionAndShape.BorderMarginBottom *= marginFactor;
- graphLabel.PositionAndShape.BorderMarginTop *= marginFactor;
- graphLabel.PositionAndShape.BorderMarginLeft *= marginFactor;
- graphLabel.PositionAndShape.BorderMarginRight *= marginFactor;
- let left: number = relative.x + graphLabel.PositionAndShape.BorderMarginLeft;
- let right: number = relative.x + graphLabel.PositionAndShape.BorderMarginRight;
- // check if GraphicalLabel exceeds the StaffLine's borders.
- if (right > staffLine.PositionAndShape.Size.width) {
- right = staffLine.PositionAndShape.Size.width - this.rules.MeasureRightMargin;
- left = right - graphLabel.PositionAndShape.MarginSize.width;
- relative.x = left - graphLabel.PositionAndShape.BorderMarginLeft;
- }
- // find allowed position (where the Label can be positioned) from Sky- BottomLine
- let drawingHeight: number;
- const skyBottomLineCalculator: SkyBottomLineCalculator = staffLine.SkyBottomLineCalculator;
- if (placement === PlacementEnum.Below) {
- drawingHeight = skyBottomLineCalculator.getBottomLineMaxInRange(left, right);
- } else {
- drawingHeight = skyBottomLineCalculator.getSkyLineMinInRange(left, right);
- }
- // set RelativePosition
- graphLabel.PositionAndShape.RelativePosition = new PointF2D(relative.x, drawingHeight);
- // update Sky- BottomLine
- if (placement === PlacementEnum.Below) {
- skyBottomLineCalculator.updateBottomLineInRange(left, right, graphLabel.PositionAndShape.BorderMarginBottom + drawingHeight);
- } else {
- skyBottomLineCalculator.updateSkyLineInRange(left, right, graphLabel.PositionAndShape.BorderMarginTop + drawingHeight);
- }
- return graphLabel;
- }
- protected calculateTempoExpressionsForMultiTempoExpression(sourceMeasure: SourceMeasure, multiTempoExpression: MultiTempoExpression,
- measureIndex: number): void {
- // calculate absolute Timestamp
- const absoluteTimestamp: Fraction = Fraction.plus(sourceMeasure.AbsoluteTimestamp, multiTempoExpression.Timestamp);
- const measures: GraphicalMeasure[] = this.graphicalMusicSheet.MeasureList[measureIndex];
- let relative: PointF2D = new PointF2D();
- if (multiTempoExpression.ContinuousTempo || multiTempoExpression.InstantaneousTempo) {
- // TempoExpressions always on the first visible System's StaffLine
- let staffLine: StaffLine = measures[0].ParentStaffLine;
- let firstVisibleMeasureX: number = measures[0].PositionAndShape.RelativePosition.x;
- let verticalIndex: number = 0;
- for (let j: number = 0; j < measures.length; j++) {
- if (!measures[j].ParentStaffLine || measures[j].ParentStaffLine.Measures.length === 0) {
- continue;
- }
- if (measures[j].ParentStaffLine.Measures.length > 0) {
- staffLine = measures[j].ParentStaffLine;
- firstVisibleMeasureX = measures[j].PositionAndShape.RelativePosition.x;
- verticalIndex = j;
- break;
- }
- }
- relative = this.getRelativePositionInStaffLineFromTimestamp(absoluteTimestamp,
- verticalIndex,
- staffLine,
- staffLine.isPartOfMultiStaffInstrument(),
- firstVisibleMeasureX);
- // also placement Above
- if (multiTempoExpression.EntriesList.length > 0 &&
- multiTempoExpression.EntriesList[0].Expression instanceof InstantaneousTempoExpression) {
- const instantaniousTempo: InstantaneousTempoExpression = (multiTempoExpression.EntriesList[0].Expression as InstantaneousTempoExpression);
- instantaniousTempo.Placement = PlacementEnum.Above;
- // if an InstantaniousTempoExpression exists at the very beginning then
- // check if expression is positioned at first ever StaffEntry and
- // check if MusicSystem is first MusicSystem
- if (staffLine.Measures[0].staffEntries.length > 0 &&
- Math.abs(relative.x - staffLine.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x) === 0 &&
- staffLine.ParentMusicSystem === staffLine.ParentMusicSystem.Parent.MusicSystems[0]) {
- const firstInstructionEntry: GraphicalStaffEntry = staffLine.Measures[0].FirstInstructionStaffEntry;
- if (firstInstructionEntry) {
- const lastInstruction: AbstractGraphicalInstruction = firstInstructionEntry.GraphicalInstructions.last();
- relative.x = lastInstruction.PositionAndShape.RelativePosition.x;
- }
- if (EngravingRules.Rules.CompactMode) {
- relative.x = staffLine.PositionAndShape.RelativePosition.x +
- staffLine.Measures[0].PositionAndShape.RelativePosition.x;
- }
- }
- }
- // const addAtLastList: GraphicalObject[] = [];
- for (const entry of multiTempoExpression.EntriesList) {
- let textAlignment: TextAlignmentEnum = TextAlignmentEnum.CenterBottom;
- if (EngravingRules.Rules.CompactMode) {
- textAlignment = TextAlignmentEnum.LeftBottom;
- }
- const graphLabel: GraphicalLabel = this.calculateLabel(staffLine,
- relative,
- entry.label,
- multiTempoExpression.getFontstyleOfFirstEntry(),
- entry.Expression.Placement,
- EngravingRules.Rules.UnknownTextHeight,
- textAlignment);
- if (entry.Expression instanceof InstantaneousTempoExpression) {
- let alreadyAdded: boolean = false;
- for (const expr of staffLine.AbstractExpressions) {
- if (expr instanceof GraphicalInstantaneousTempoExpression &&
- (expr.SourceExpression as AbstractTempoExpression).Label === entry.Expression.Label) {
- alreadyAdded = true;
- }
- }
- if (alreadyAdded) {
- continue;
- }
- const graphicalTempoExpr: GraphicalInstantaneousTempoExpression = new GraphicalInstantaneousTempoExpression(entry.Expression, graphLabel);
- if (graphicalTempoExpr.ParentStaffLine === undefined) {
- log.warn("Adding staffline didn't work");
- // I am actually fooling the linter her and use the created object. This method needs refactoring,
- // all graphical expression creations should be in one place and ahve basic stuff like labels, lines, ...
- // in their constructor
- }
- // in case of metronome mark:
- if ((entry.Expression as InstantaneousTempoExpression).Enum === TempoEnum.metronomeMark) {
- // use smaller font:
- graphLabel.Label.fontHeight = 1.2;
- }
- } else if (entry.Expression instanceof ContinuousTempoExpression) {
- // FIXME: Not yet implemented
- // let alreadyAdded: boolean = false;
- // for (const expr of staffLine.AbstractExpressions) {
- // if (expr instanceof GraphicalContinuousTempoExpression &&
- // expr.GetContinuousTempoExpression.Label === entry.Expression.Label) {
- // alreadyAdded = true;
- // }
- // }
- // if (alreadyAdded) {
- // continue;
- // }
- // staffLine.AbstractExpressions.push(new GraphicalContinuousTempoExpression((ContinuousTempoExpression)(entry.Expression), graphLabel));
- }
- }
- }
- }
- protected graphicalMeasureCreatedCalculations(measure: GraphicalMeasure): void {
- return;
- }
- protected clearSystemsAndMeasures(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
- const graphicalMeasure: GraphicalMeasure = staffLine.Measures[idx4];
- if (graphicalMeasure.FirstInstructionStaffEntry !== undefined) {
- const index: number = graphicalMeasure.PositionAndShape.ChildElements.indexOf(
- graphicalMeasure.FirstInstructionStaffEntry.PositionAndShape
- );
- if (index > -1) {
- graphicalMeasure.PositionAndShape.ChildElements.splice(index, 1);
- }
- graphicalMeasure.FirstInstructionStaffEntry = undefined;
- graphicalMeasure.beginInstructionsWidth = 0.0;
- }
- if (graphicalMeasure.LastInstructionStaffEntry !== undefined) {
- const index: number = graphicalMeasure.PositionAndShape.ChildElements.indexOf(
- graphicalMeasure.LastInstructionStaffEntry.PositionAndShape
- );
- if (index > -1) {
- graphicalMeasure.PositionAndShape.ChildElements.splice(index, 1);
- }
- graphicalMeasure.LastInstructionStaffEntry = undefined;
- graphicalMeasure.endInstructionsWidth = 0.0;
- }
- }
- staffLine.Measures = [];
- staffLine.PositionAndShape.ChildElements = [];
- }
- musicSystem.StaffLines.length = 0;
- musicSystem.PositionAndShape.ChildElements = [];
- }
- graphicalMusicPage.MusicSystems = [];
- graphicalMusicPage.PositionAndShape.ChildElements = [];
- }
- this.graphicalMusicSheet.MusicPages = [];
- }
- protected handleVoiceEntry(voiceEntry: VoiceEntry, graphicalStaffEntry: GraphicalStaffEntry,
- accidentalCalculator: AccidentalCalculator, openLyricWords: LyricWord[],
- activeClef: ClefInstruction,
- openTuplets: Tuplet[], openBeams: Beam[],
- octaveShiftValue: OctaveEnum, linkedNotes: Note[] = undefined,
- sourceStaffEntry: SourceStaffEntry = undefined): OctaveEnum {
- if (voiceEntry.WantedStemDirectionXml !== StemDirectionType.Undefined &&
- EngravingRules.Rules.SetWantedStemDirectionByXml &&
- voiceEntry.WantedStemDirectionXml !== undefined) {
- voiceEntry.WantedStemDirection = voiceEntry.WantedStemDirectionXml;
- } else {
- this.calculateStemDirectionFromVoices(voiceEntry);
- }
- const gve: GraphicalVoiceEntry = graphicalStaffEntry.findOrCreateGraphicalVoiceEntry(voiceEntry);
- gve.octaveShiftValue = octaveShiftValue;
- for (let idx: number = 0, len: number = voiceEntry.Notes.length; idx < len; ++idx) {
- const note: Note = voiceEntry.Notes[idx];
- if (note === undefined) {
- continue;
- }
- if (sourceStaffEntry !== undefined && sourceStaffEntry.Link !== undefined && linkedNotes !== undefined && linkedNotes.indexOf(note) > -1) {
- continue;
- }
- let graphicalNote: GraphicalNote;
- if (voiceEntry.IsGrace) {
- graphicalNote = MusicSheetCalculator.symbolFactory.createGraceNote(note, gve, activeClef, octaveShiftValue);
- } else {
- graphicalNote = MusicSheetCalculator.symbolFactory.createNote(note, gve, activeClef, octaveShiftValue, undefined);
- }
- if (note.Pitch !== undefined) {
- this.checkNoteForAccidental(graphicalNote, accidentalCalculator, activeClef, octaveShiftValue);
- }
- this.resetYPositionForLeadSheet(graphicalNote.PositionAndShape);
- graphicalStaffEntry.addGraphicalNoteToListAtCorrectYPosition(gve, graphicalNote);
- graphicalNote.PositionAndShape.calculateBoundingBox();
- if (!this.leadSheet) {
- if (note.NoteBeam !== undefined && note.PrintObject) {
- this.handleBeam(graphicalNote, note.NoteBeam, openBeams);
- }
- if (note.NoteTuplet !== undefined && note.PrintObject) {
- this.handleTuplet(graphicalNote, note.NoteTuplet, openTuplets);
- }
- }
- }
- if (voiceEntry.Articulations.length > 0) {
- this.handleVoiceEntryArticulations(voiceEntry.Articulations, voiceEntry, graphicalStaffEntry);
- }
- if (voiceEntry.TechnicalInstructions.length > 0) {
- this.handleVoiceEntryTechnicalInstructions(voiceEntry.TechnicalInstructions, voiceEntry, graphicalStaffEntry);
- }
- if (voiceEntry.LyricsEntries.size() > 0) {
- this.handleVoiceEntryLyrics(voiceEntry, graphicalStaffEntry, openLyricWords);
- }
- if (voiceEntry.OrnamentContainer !== undefined) {
- this.handleVoiceEntryOrnaments(voiceEntry.OrnamentContainer, voiceEntry, graphicalStaffEntry);
- }
- return octaveShiftValue;
- }
- protected resetYPositionForLeadSheet(psi: BoundingBox): void {
- if (this.leadSheet) {
- psi.RelativePosition = new PointF2D(psi.RelativePosition.x, 0.0);
- }
- }
- protected layoutVoiceEntries(graphicalStaffEntry: GraphicalStaffEntry): void {
- graphicalStaffEntry.PositionAndShape.RelativePosition = new PointF2D(0.0, 0.0);
- if (!this.leadSheet) {
- for (const gve of graphicalStaffEntry.graphicalVoiceEntries) {
- const graphicalNotes: GraphicalNote[] = gve.notes;
- if (graphicalNotes.length === 0) {
- continue;
- }
- const voiceEntry: VoiceEntry = graphicalNotes[0].sourceNote.ParentVoiceEntry;
- const hasPitchedNote: boolean = graphicalNotes[0].sourceNote.Pitch !== undefined;
- this.layoutVoiceEntry(voiceEntry, graphicalNotes, graphicalStaffEntry, hasPitchedNote);
- }
- }
- }
- protected maxInstrNameLabelLength(): number {
- if (!EngravingRules.Rules.RenderInstrumentNames) {
- return 0;
- }
- let maxLabelLength: number = 0.0;
- for (const instrument of this.graphicalMusicSheet.ParentMusicSheet.Instruments) {
- if (instrument.Voices.length > 0 && instrument.Voices[0].Visible) {
- const graphicalLabel: GraphicalLabel = new GraphicalLabel(
- instrument.NameLabel, this.rules.InstrumentLabelTextHeight, TextAlignmentEnum.LeftCenter);
- graphicalLabel.setLabelPositionAndShapeBorders();
- maxLabelLength = Math.max(maxLabelLength, graphicalLabel.PositionAndShape.MarginSize.width);
- }
- }
- return maxLabelLength;
- }
- protected calculateSheetLabelBoundingBoxes(): void {
- const musicSheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
- if (musicSheet.Title !== undefined && EngravingRules.Rules.RenderTitle) {
- const title: GraphicalLabel = new GraphicalLabel(musicSheet.Title, this.rules.SheetTitleHeight, TextAlignmentEnum.CenterBottom);
- this.graphicalMusicSheet.Title = title;
- title.setLabelPositionAndShapeBorders();
- } else if (!EngravingRules.Rules.RenderTitle) {
- this.graphicalMusicSheet.Title = undefined; // clear label if rendering it was disabled after last render
- }
- if (musicSheet.Subtitle !== undefined && EngravingRules.Rules.RenderSubtitle) {
- const subtitle: GraphicalLabel = new GraphicalLabel(musicSheet.Subtitle, this.rules.SheetSubtitleHeight, TextAlignmentEnum.CenterCenter);
- this.graphicalMusicSheet.Subtitle = subtitle;
- subtitle.setLabelPositionAndShapeBorders();
- } else if (!EngravingRules.Rules.RenderSubtitle) {
- this.graphicalMusicSheet.Subtitle = undefined;
- }
- if (musicSheet.Composer !== undefined && EngravingRules.Rules.RenderComposer) {
- const composer: GraphicalLabel = new GraphicalLabel(musicSheet.Composer, this.rules.SheetComposerHeight, TextAlignmentEnum.RightCenter);
- this.graphicalMusicSheet.Composer = composer;
- composer.setLabelPositionAndShapeBorders();
- } else if (!EngravingRules.Rules.RenderComposer) {
- this.graphicalMusicSheet.Composer = undefined;
- }
- if (musicSheet.Lyricist !== undefined && EngravingRules.Rules.RenderLyricist) {
- const lyricist: GraphicalLabel = new GraphicalLabel(musicSheet.Lyricist, this.rules.SheetAuthorHeight, TextAlignmentEnum.LeftCenter);
- this.graphicalMusicSheet.Lyricist = lyricist;
- lyricist.setLabelPositionAndShapeBorders();
- } else if (!EngravingRules.Rules.RenderLyricist) {
- this.graphicalMusicSheet.Lyricist = undefined;
- }
- }
- protected checkMeasuresForWholeRestNotes(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const musicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = musicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = musicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
- const measure: GraphicalMeasure = staffLine.Measures[idx4];
- if (measure.staffEntries.length === 1) {
- const gse: GraphicalStaffEntry = measure.staffEntries[0];
- if (gse.graphicalVoiceEntries.length > 0 && gse.graphicalVoiceEntries[0].notes.length === 1) {
- const graphicalNote: GraphicalNote = gse.graphicalVoiceEntries[0].notes[0];
- if (graphicalNote.sourceNote.Pitch === undefined && (new Fraction(1, 2)).lt(graphicalNote.sourceNote.Length)) {
- this.layoutMeasureWithWholeRest(graphicalNote, gse, measure);
- }
- }
- }
- }
- }
- }
- }
- }
- protected optimizeRestNotePlacement(graphicalStaffEntry: GraphicalStaffEntry, measure: GraphicalMeasure): void {
- if (graphicalStaffEntry.graphicalVoiceEntries.length === 0) {
- return;
- }
- const voice1Notes: GraphicalNote[] = graphicalStaffEntry.graphicalVoiceEntries[0].notes;
- if (voice1Notes.length === 0) {
- return;
- }
- const voice1Note1: GraphicalNote = voice1Notes[0];
- const voice1Note1IsRest: boolean = voice1Note1.sourceNote.Pitch === undefined;
- if (graphicalStaffEntry.graphicalVoiceEntries.length === 2) {
- let voice2Note1IsRest: boolean = false;
- const voice2Notes: GraphicalNote[] = graphicalStaffEntry.graphicalVoiceEntries[1].notes;
- if (voice2Notes.length > 0) {
- const voice2Note1: GraphicalNote = voice2Notes[0];
- voice2Note1IsRest = voice2Note1.sourceNote.Pitch === undefined;
- }
- if (voice1Note1IsRest && voice2Note1IsRest) {
- this.calculateTwoRestNotesPlacementWithCollisionDetection(graphicalStaffEntry);
- } else if (voice1Note1IsRest || voice2Note1IsRest) {
- this.calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(graphicalStaffEntry);
- }
- } else if (voice1Note1IsRest && graphicalStaffEntry !== measure.staffEntries[0] &&
- graphicalStaffEntry !== measure.staffEntries[measure.staffEntries.length - 1]) {
- const staffEntryIndex: number = measure.staffEntries.indexOf(graphicalStaffEntry);
- const previousStaffEntry: GraphicalStaffEntry = measure.staffEntries[staffEntryIndex - 1];
- const nextStaffEntry: GraphicalStaffEntry = measure.staffEntries[staffEntryIndex + 1];
- if (previousStaffEntry.graphicalVoiceEntries.length === 1) {
- const previousNote: GraphicalNote = previousStaffEntry.graphicalVoiceEntries[0].notes[0];
- if (previousNote.sourceNote.NoteBeam !== undefined && nextStaffEntry.graphicalVoiceEntries.length === 1) {
- const nextNote: GraphicalNote = nextStaffEntry.graphicalVoiceEntries[0].notes[0];
- if (nextNote.sourceNote.NoteBeam !== undefined && previousNote.sourceNote.NoteBeam === nextNote.sourceNote.NoteBeam) {
- this.calculateRestNotePlacementWithinGraphicalBeam(
- graphicalStaffEntry, voice1Note1, previousNote,
- nextStaffEntry, nextNote
- );
- graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
- }
- }
- }
- }
- }
- protected getRelativePositionInStaffLineFromTimestamp(timestamp: Fraction, verticalIndex: number, staffLine: StaffLine,
- multiStaffInstrument: boolean, firstVisibleMeasureRelativeX: number = 0.0): PointF2D {
- let relative: PointF2D = new PointF2D();
- let leftStaffEntry: GraphicalStaffEntry = undefined;
- let rightStaffEntry: GraphicalStaffEntry = undefined;
- const numEntries: number = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
- const index: number = this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(timestamp);
- const leftIndex: number = Math.min(Math.floor(index), numEntries - 1);
- const rightIndex: number = Math.min(Math.ceil(index), numEntries - 1);
- if (leftIndex < 0 || verticalIndex < 0) {
- return relative;
- }
- leftStaffEntry = this.getFirstLeftNotNullStaffEntryFromContainer(leftIndex, verticalIndex, multiStaffInstrument);
- rightStaffEntry = this.getFirstRightNotNullStaffEntryFromContainer(rightIndex, verticalIndex, multiStaffInstrument);
- if (leftStaffEntry !== undefined && rightStaffEntry !== undefined) {
- let measureRelativeX: number = leftStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x;
- if (firstVisibleMeasureRelativeX > 0) {
- measureRelativeX = firstVisibleMeasureRelativeX;
- }
- let leftX: number = leftStaffEntry.PositionAndShape.RelativePosition.x + measureRelativeX;
- let rightX: number = rightStaffEntry.PositionAndShape.RelativePosition.x + rightStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x;
- if (firstVisibleMeasureRelativeX > 0) {
- rightX = rightStaffEntry.PositionAndShape.RelativePosition.x + measureRelativeX;
- }
- let timestampQuotient: number = 0.0;
- if (leftStaffEntry !== rightStaffEntry) {
- const leftTimestamp: Fraction = leftStaffEntry.getAbsoluteTimestamp();
- const rightTimestamp: Fraction = rightStaffEntry.getAbsoluteTimestamp();
- const leftDifference: Fraction = Fraction.minus(timestamp, leftTimestamp);
- timestampQuotient = leftDifference.RealValue / Fraction.minus(rightTimestamp, leftTimestamp).RealValue;
- }
- if (leftStaffEntry.parentMeasure.ParentStaffLine !== rightStaffEntry.parentMeasure.ParentStaffLine) {
- if (leftStaffEntry.parentMeasure.ParentStaffLine === staffLine) {
- rightX = staffLine.PositionAndShape.Size.width;
- } else {
- leftX = staffLine.PositionAndShape.RelativePosition.x;
- }
- }
- relative = new PointF2D(leftX + (rightX - leftX) * timestampQuotient, 0.0);
- }
- return relative;
- }
- protected getRelativeXPositionFromTimestamp(timestamp: Fraction): number {
- const numEntries: number = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
- const index: number = this.graphicalMusicSheet.GetInterpolatedIndexInVerticalContainers(timestamp);
- const discreteIndex: number = Math.max(0, Math.min(Math.round(index), numEntries - 1));
- const gse: GraphicalStaffEntry = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[discreteIndex].getFirstNonNullStaffEntry();
- const posX: number = gse.PositionAndShape.RelativePosition.x + gse.parentMeasure.PositionAndShape.RelativePosition.x;
- return posX;
- }
- protected calculatePageLabels(page: GraphicalMusicPage): void {
- // The PositionAndShape child elements of page need to be manually connected to the lyricist, composer, subtitle, etc.
- // because the page is only available now
- let firstSystemAbsoluteTopMargin: number = 10;
- if (page.MusicSystems.length > 0) {
- const firstMusicSystem: MusicSystem = page.MusicSystems[0];
- firstSystemAbsoluteTopMargin = firstMusicSystem.PositionAndShape.RelativePosition.y + firstMusicSystem.PositionAndShape.BorderTop;
- }
- if (this.graphicalMusicSheet.Title !== undefined) {
- const title: GraphicalLabel = this.graphicalMusicSheet.Title;
- title.PositionAndShape.Parent = page.PositionAndShape;
- const relative: PointF2D = new PointF2D();
- relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth / 2;
- relative.y = this.rules.TitleTopDistance + this.rules.SheetTitleHeight;
- title.PositionAndShape.RelativePosition = relative;
- page.Labels.push(title);
- }
- if (this.graphicalMusicSheet.Subtitle !== undefined) {
- const subtitle: GraphicalLabel = this.graphicalMusicSheet.Subtitle;
- subtitle.PositionAndShape.Parent = page.PositionAndShape;
- const relative: PointF2D = new PointF2D();
- relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth / 2;
- relative.y = this.rules.TitleTopDistance + this.rules.SheetTitleHeight + this.rules.SheetMinimumDistanceBetweenTitleAndSubtitle;
- subtitle.PositionAndShape.RelativePosition = relative;
- page.Labels.push(subtitle);
- }
- if (this.graphicalMusicSheet.Composer !== undefined) {
- const composer: GraphicalLabel = this.graphicalMusicSheet.Composer;
- composer.PositionAndShape.Parent = page.PositionAndShape;
- composer.setLabelPositionAndShapeBorders();
- const relative: PointF2D = new PointF2D();
- relative.x = this.graphicalMusicSheet.ParentMusicSheet.pageWidth - this.rules.PageRightMargin;
- relative.y = firstSystemAbsoluteTopMargin - this.rules.SystemComposerDistance;
- composer.PositionAndShape.RelativePosition = relative;
- page.Labels.push(composer);
- }
- if (this.graphicalMusicSheet.Lyricist !== undefined) {
- const lyricist: GraphicalLabel = this.graphicalMusicSheet.Lyricist;
- lyricist.PositionAndShape.Parent = page.PositionAndShape;
- lyricist.setLabelPositionAndShapeBorders();
- const relative: PointF2D = new PointF2D();
- relative.x = this.rules.PageLeftMargin;
- relative.y = firstSystemAbsoluteTopMargin - this.rules.SystemComposerDistance;
- lyricist.PositionAndShape.RelativePosition = relative;
- page.Labels.push(lyricist);
- }
- }
- protected createGraphicalTies(): void {
- for (let measureIndex: number = 0; measureIndex < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; measureIndex++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[measureIndex];
- for (let staffIndex: number = 0; staffIndex < sourceMeasure.CompleteNumberOfStaves; staffIndex++) {
- for (let j: number = 0; j < sourceMeasure.VerticalSourceStaffEntryContainers.length; j++) {
- const sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[j].StaffEntries[staffIndex];
- if (sourceStaffEntry !== undefined) {
- const startStaffEntry: GraphicalStaffEntry = this.graphicalMusicSheet.findGraphicalStaffEntryFromMeasureList(
- staffIndex, measureIndex, sourceStaffEntry
- );
- for (let idx: number = 0, len: number = sourceStaffEntry.VoiceEntries.length; idx < len; ++idx) {
- const voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
- for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
- const note: Note = voiceEntry.Notes[idx2];
- if (note.NoteTie !== undefined) {
- const tie: Tie = note.NoteTie;
- this.handleTie(tie, startStaffEntry, staffIndex, measureIndex);
- }
- }
- }
- }
- }
- }
- }
- }
- private handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number, measureIndex: number): void {
- let startGse: GraphicalStaffEntry = startGraphicalStaffEntry;
- let startNote: GraphicalNote = startGse.findEndTieGraphicalNoteFromNote(tie.StartNote);
- let endGse: GraphicalStaffEntry = undefined;
- let endNote: GraphicalNote = undefined;
- for (let i: number = 1; i < tie.Notes.length; i++) {
- startNote = startGse.findEndTieGraphicalNoteFromNote(tie.Notes[i - 1]);
- endGse = this.graphicalMusicSheet.GetGraphicalFromSourceStaffEntry(tie.Notes[i].ParentStaffEntry);
- endNote = endGse.findEndTieGraphicalNoteFromNote(tie.Notes[i]);
- if (startNote !== undefined && endNote !== undefined && endGse !== undefined) {
- if (!startNote.sourceNote.PrintObject || !endNote.sourceNote.PrintObject) {
- continue;
- }
- const graphicalTie: GraphicalTie = this.createGraphicalTie(tie, startGse, endGse, startNote, endNote);
- startGse.GraphicalTies.push(graphicalTie);
- if (this.staffEntriesWithGraphicalTies.indexOf(startGse) >= 0) {
- this.staffEntriesWithGraphicalTies.push(startGse);
- }
- }
- startGse = endGse;
- }
- }
- private createAccidentalCalculators(): AccidentalCalculator[] {
- const accidentalCalculators: AccidentalCalculator[] = [];
- const firstSourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();
- if (firstSourceMeasure !== undefined) {
- for (let i: number = 0; i < firstSourceMeasure.CompleteNumberOfStaves; i++) {
- const accidentalCalculator: AccidentalCalculator = new AccidentalCalculator();
- accidentalCalculators.push(accidentalCalculator);
- if (firstSourceMeasure.FirstInstructionsStaffEntries[i] !== undefined) {
- for (let idx: number = 0, len: number = firstSourceMeasure.FirstInstructionsStaffEntries[i].Instructions.length; idx < len; ++idx) {
- const abstractNotationInstruction: AbstractNotationInstruction = firstSourceMeasure.FirstInstructionsStaffEntries[i].Instructions[idx];
- if (abstractNotationInstruction instanceof KeyInstruction) {
- const keyInstruction: KeyInstruction = <KeyInstruction>abstractNotationInstruction;
- accidentalCalculator.ActiveKeyInstruction = keyInstruction;
- }
- }
- }
- }
- }
- return accidentalCalculators;
- }
- private calculateVerticalContainersList(): void {
- const numberOfEntries: number = this.graphicalMusicSheet.MeasureList[0].length;
- for (let i: number = 0; i < this.graphicalMusicSheet.MeasureList.length; i++) {
- for (let j: number = 0; j < numberOfEntries; j++) {
- const measure: GraphicalMeasure = this.graphicalMusicSheet.MeasureList[i][j];
- for (let idx: number = 0, len: number = measure.staffEntries.length; idx < len; ++idx) {
- const graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx];
- const verticalContainer: VerticalGraphicalStaffEntryContainer =
- this.graphicalMusicSheet.getOrCreateVerticalContainer(graphicalStaffEntry.getAbsoluteTimestamp());
- if (verticalContainer !== undefined) {
- verticalContainer.StaffEntries[j] = graphicalStaffEntry;
- graphicalStaffEntry.parentVerticalContainer = verticalContainer;
- }
- }
- }
- }
- }
- private setIndicesToVerticalGraphicalContainers(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length; i++) {
- this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].Index = i;
- }
- }
- private createGraphicalMeasuresForSourceMeasure(sourceMeasure: SourceMeasure, accidentalCalculators: AccidentalCalculator[],
- openLyricWords: LyricWord[],
- openOctaveShifts: OctaveShiftParams[], activeClefs: ClefInstruction[]): GraphicalMeasure[] {
- this.initGraphicalMeasuresCreation();
- const verticalMeasureList: GraphicalMeasure[] = [];
- const openBeams: Beam[] = [];
- const openTuplets: Tuplet[] = [];
- const staffEntryLinks: StaffEntryLink[] = [];
- for (let staffIndex: number = 0; staffIndex < sourceMeasure.CompleteNumberOfStaves; staffIndex++) {
- const measure: GraphicalMeasure = this.createGraphicalMeasure(
- sourceMeasure, openTuplets, openBeams,
- accidentalCalculators[staffIndex], activeClefs, openOctaveShifts, openLyricWords, staffIndex, staffEntryLinks
- );
- this.graphicalMeasureCreatedCalculations(measure);
- verticalMeasureList.push(measure);
- }
- this.graphicalMusicSheet.sourceToGraphicalMeasureLinks.setValue(sourceMeasure, verticalMeasureList);
- return verticalMeasureList;
- }
- private createGraphicalMeasure(sourceMeasure: SourceMeasure, openTuplets: Tuplet[], openBeams: Beam[],
- accidentalCalculator: AccidentalCalculator, activeClefs: ClefInstruction[],
- openOctaveShifts: OctaveShiftParams[], openLyricWords: LyricWord[], staffIndex: number,
- staffEntryLinks: StaffEntryLink[]): GraphicalMeasure {
- const staff: Staff = this.graphicalMusicSheet.ParentMusicSheet.getStaffFromIndex(staffIndex);
- const measure: GraphicalMeasure = MusicSheetCalculator.symbolFactory.createGraphicalMeasure(sourceMeasure, staff);
- measure.hasError = sourceMeasure.getErrorInMeasure(staffIndex);
- if (sourceMeasure.FirstInstructionsStaffEntries[staffIndex] !== undefined) {
- for (let idx: number = 0, len: number = sourceMeasure.FirstInstructionsStaffEntries[staffIndex].Instructions.length; idx < len; ++idx) {
- const instruction: AbstractNotationInstruction = sourceMeasure.FirstInstructionsStaffEntries[staffIndex].Instructions[idx];
- if (instruction instanceof KeyInstruction) {
- const key: KeyInstruction = KeyInstruction.copy(instruction);
- if (this.graphicalMusicSheet.ParentMusicSheet.Transpose !== 0 &&
- measure.ParentStaff.ParentInstrument.MidiInstrumentId !== MidiInstrument.Percussion &&
- MusicSheetCalculator.transposeCalculator !== undefined) {
- MusicSheetCalculator.transposeCalculator.transposeKey(
- key, this.graphicalMusicSheet.ParentMusicSheet.Transpose
- );
- }
- accidentalCalculator.ActiveKeyInstruction = key;
- }
- }
- }
- for (let idx: number = 0, len: number = sourceMeasure.StaffLinkedExpressions[staffIndex].length; idx < len; ++idx) {
- const multiExpression: MultiExpression = sourceMeasure.StaffLinkedExpressions[staffIndex][idx];
- if (multiExpression.OctaveShiftStart !== undefined) {
- const openOctaveShift: OctaveShift = multiExpression.OctaveShiftStart;
- openOctaveShifts[staffIndex] = new OctaveShiftParams(
- openOctaveShift, multiExpression.AbsoluteTimestamp,
- openOctaveShift.ParentEndMultiExpression.AbsoluteTimestamp
- );
- }
- }
- for (let entryIndex: number = 0; entryIndex < sourceMeasure.VerticalSourceStaffEntryContainers.length; entryIndex++) {
- const sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[entryIndex].StaffEntries[staffIndex];
- if (sourceStaffEntry !== undefined) {
- for (let idx: number = 0, len: number = sourceStaffEntry.Instructions.length; idx < len; ++idx) {
- const abstractNotationInstruction: AbstractNotationInstruction = sourceStaffEntry.Instructions[idx];
- if (abstractNotationInstruction instanceof ClefInstruction) {
- activeClefs[staffIndex] = <ClefInstruction>abstractNotationInstruction;
- }
- }
- const graphicalStaffEntry: GraphicalStaffEntry = MusicSheetCalculator.symbolFactory.createStaffEntry(sourceStaffEntry, measure);
- if (measure.staffEntries.length > entryIndex) {
- measure.addGraphicalStaffEntryAtTimestamp(graphicalStaffEntry);
- } else {
- measure.addGraphicalStaffEntry(graphicalStaffEntry);
- }
- const linkedNotes: Note[] = [];
- if (sourceStaffEntry.Link !== undefined) {
- sourceStaffEntry.findLinkedNotes(linkedNotes);
- this.handleStaffEntryLink(graphicalStaffEntry, staffEntryLinks);
- }
- let octaveShiftValue: OctaveEnum = OctaveEnum.NONE;
- if (openOctaveShifts[staffIndex] !== undefined) {
- const octaveShiftParams: OctaveShiftParams = openOctaveShifts[staffIndex];
- if (octaveShiftParams.getAbsoluteStartTimestamp.lte(sourceStaffEntry.AbsoluteTimestamp) &&
- sourceStaffEntry.AbsoluteTimestamp.lte(octaveShiftParams.getAbsoluteEndTimestamp)) {
- octaveShiftValue = octaveShiftParams.getOpenOctaveShift.Type;
- }
- }
- for (let idx: number = 0, len: number = sourceStaffEntry.VoiceEntries.length; idx < len; ++idx) {
- const voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
- octaveShiftValue = this.handleVoiceEntry(
- voiceEntry, graphicalStaffEntry,
- accidentalCalculator, openLyricWords,
- activeClefs[staffIndex], openTuplets,
- openBeams, octaveShiftValue, linkedNotes,
- sourceStaffEntry
- );
- }
- if (sourceStaffEntry.Instructions.length > 0) {
- const clefInstruction: ClefInstruction = <ClefInstruction>sourceStaffEntry.Instructions[0];
- MusicSheetCalculator.symbolFactory.createInStaffClef(graphicalStaffEntry, clefInstruction);
- }
- if (sourceStaffEntry.ChordContainer !== undefined) {
- sourceStaffEntry.ParentStaff.ParentInstrument.HasChordSymbols = true;
- MusicSheetCalculator.symbolFactory.createChordSymbol(
- sourceStaffEntry,
- graphicalStaffEntry,
- this.graphicalMusicSheet.ParentMusicSheet.Transpose);
- }
- }
- }
- accidentalCalculator.doCalculationsAtEndOfMeasure();
- if (sourceMeasure.LastInstructionsStaffEntries[staffIndex] !== undefined) {
- const lastStaffEntry: SourceStaffEntry = sourceMeasure.LastInstructionsStaffEntries[staffIndex];
- for (let idx: number = 0, len: number = lastStaffEntry.Instructions.length; idx < len; ++idx) {
- const abstractNotationInstruction: AbstractNotationInstruction = lastStaffEntry.Instructions[idx];
- if (abstractNotationInstruction instanceof ClefInstruction) {
- activeClefs[staffIndex] = <ClefInstruction>abstractNotationInstruction;
- }
- }
- }
- for (let idx: number = 0, len: number = sourceMeasure.StaffLinkedExpressions[staffIndex].length; idx < len; ++idx) {
- const multiExpression: MultiExpression = sourceMeasure.StaffLinkedExpressions[staffIndex][idx];
- if (multiExpression.OctaveShiftEnd !== undefined && openOctaveShifts[staffIndex] !== undefined &&
- multiExpression.OctaveShiftEnd === openOctaveShifts[staffIndex].getOpenOctaveShift) {
- openOctaveShifts[staffIndex] = undefined;
- }
- }
- // check wantedStemDirections of beam notes at end of measure (e.g. for beam with grace notes)
- for (const staffEntry of measure.staffEntries) {
- for (const voiceEntry of staffEntry.graphicalVoiceEntries) {
- this.setBeamNotesWantedStemDirections(voiceEntry.parentVoiceEntry);
- }
- }
- // if there are no staffEntries in this measure, create a rest for the whole measure:
- if (measure.staffEntries.length === 0) {
- const sourceStaffEntry: SourceStaffEntry = new SourceStaffEntry(
- new VerticalSourceStaffEntryContainer(measure.parentSourceMeasure,
- measure.parentSourceMeasure.AbsoluteTimestamp,
- measure.parentSourceMeasure.CompleteNumberOfStaves),
- staff);
- const voiceEntry: VoiceEntry = new VoiceEntry(new Fraction(0, 1), staff.Voices[0], sourceStaffEntry);
- const note: Note = new Note(voiceEntry, sourceStaffEntry, Fraction.createFromFraction(sourceMeasure.Duration), undefined);
- voiceEntry.Notes.push(note);
- const graphicalStaffEntry: GraphicalStaffEntry = MusicSheetCalculator.symbolFactory.createStaffEntry(sourceStaffEntry, measure);
- measure.addGraphicalStaffEntry(graphicalStaffEntry);
- graphicalStaffEntry.relInMeasureTimestamp = voiceEntry.Timestamp;
- const gve: GraphicalVoiceEntry = MusicSheetCalculator.symbolFactory.createVoiceEntry(voiceEntry, graphicalStaffEntry);
- graphicalStaffEntry.graphicalVoiceEntries.push(gve);
- const graphicalNote: GraphicalNote = MusicSheetCalculator.symbolFactory.createNote(note,
- gve,
- new ClefInstruction(),
- OctaveEnum.NONE, undefined);
- gve.notes.push(graphicalNote);
- }
- return measure;
- }
- private checkNoteForAccidental(graphicalNote: GraphicalNote, accidentalCalculator: AccidentalCalculator, activeClef: ClefInstruction,
- octaveEnum: OctaveEnum): void {
- let pitch: Pitch = graphicalNote.sourceNote.Pitch;
- const transpose: number = this.graphicalMusicSheet.ParentMusicSheet.Transpose;
- if (transpose !== 0 && graphicalNote.sourceNote.ParentStaffEntry.ParentStaff.ParentInstrument.MidiInstrumentId !== MidiInstrument.Percussion) {
- pitch = graphicalNote.Transpose(
- accidentalCalculator.ActiveKeyInstruction, activeClef, transpose, octaveEnum
- );
- }
- graphicalNote.sourceNote.halfTone = pitch.getHalfTone();
- accidentalCalculator.checkAccidental(graphicalNote, pitch);
- }
- // // needed to disable linter, as it doesn't recognize the existing usage of this method.
- // // ToDo: check if a newer version doesn't have the problem.
- // /* tslint:disable:no-unused-variable */
- // private createStaffEntryForTieNote(measure: StaffMeasure, absoluteTimestamp: Fraction, openTie: Tie): GraphicalStaffEntry {
- // /* tslint:enable:no-unused-variable */
- // let graphicalStaffEntry: GraphicalStaffEntry;
- // graphicalStaffEntry = MusicSheetCalculator.symbolFactory.createStaffEntry(openTie.Start.ParentStaffEntry, measure);
- // graphicalStaffEntry.relInMeasureTimestamp = Fraction.minus(absoluteTimestamp, measure.parentSourceMeasure.AbsoluteTimestamp);
- // this.resetYPositionForLeadSheet(graphicalStaffEntry.PositionAndShape);
- // measure.addGraphicalStaffEntryAtTimestamp(graphicalStaffEntry);
- // return graphicalStaffEntry;
- // }
- private handleStaffEntries(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MeasureList.length; idx < len; ++idx) {
- const measures: GraphicalMeasure[] = this.graphicalMusicSheet.MeasureList[idx];
- for (let idx2: number = 0, len2: number = measures.length; idx2 < len2; ++idx2) {
- const measure: GraphicalMeasure = measures[idx2];
- for (const graphicalStaffEntry of measure.staffEntries) {
- if (graphicalStaffEntry.parentMeasure !== undefined
- && graphicalStaffEntry.graphicalVoiceEntries.length > 0
- && graphicalStaffEntry.graphicalVoiceEntries[0].notes.length > 0) {
- this.layoutVoiceEntries(graphicalStaffEntry);
- this.layoutStaffEntry(graphicalStaffEntry);
- }
- }
- }
- }
- }
- private calculateSkyBottomLines(): void {
- for (const graphicalMusicPage of this.graphicalMusicSheet.MusicPages) {
- for (const musicSystem of graphicalMusicPage.MusicSystems) {
- for (const staffLine of musicSystem.StaffLines) {
- staffLine.SkyBottomLineCalculator.calculateLines();
- }
- }
- }
- }
- /**
- * Re-adjust the x positioning of expressions. Update the skyline afterwards
- */
- private calculateExpressionAlignements(): void {
- for (const graphicalMusicPage of this.graphicalMusicSheet.MusicPages) {
- for (const musicSystem of graphicalMusicPage.MusicSystems) {
- for (const staffLine of musicSystem.StaffLines) {
- staffLine.AlignmentManager.alignDynamicExpressions();
- staffLine.AbstractExpressions.forEach(ae => ae.updateSkyBottomLine());
- }
- }
- }
- }
- private calculateBeams(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const musicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = musicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = musicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = staffLine.Measures.length; idx4 < len4; ++idx4) {
- const measure: GraphicalMeasure = staffLine.Measures[idx4];
- for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
- const staffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
- this.layoutBeams(staffEntry);
- }
- }
- }
- }
- }
- }
- private calculateStaffEntryArticulationMarks(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
- const system: MusicSystem = page.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
- const line: StaffLine = system.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
- const measure: GraphicalMeasure = line.Measures[idx4];
- for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
- const graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
- for (let idx6: number = 0, len6: number = graphicalStaffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
- const voiceEntry: VoiceEntry = graphicalStaffEntry.sourceStaffEntry.VoiceEntries[idx6];
- if (voiceEntry.Articulations.length > 0) {
- this.layoutArticulationMarks(voiceEntry.Articulations, voiceEntry, graphicalStaffEntry);
- }
- }
- }
- }
- }
- }
- }
- }
- private calculateOrnaments(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
- const system: MusicSystem = page.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
- const line: StaffLine = system.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
- const measure: GraphicalMeasure = line.Measures[idx4];
- for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
- const graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
- for (let idx6: number = 0, len6: number = graphicalStaffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
- const voiceEntry: VoiceEntry = graphicalStaffEntry.sourceStaffEntry.VoiceEntries[idx6];
- if (voiceEntry.OrnamentContainer !== undefined) {
- if (voiceEntry.hasTie() && !graphicalStaffEntry.relInMeasureTimestamp.Equals(voiceEntry.Timestamp)) {
- continue;
- }
- this.layoutOrnament(voiceEntry.OrnamentContainer, voiceEntry, graphicalStaffEntry);
- if (!(this.staffEntriesWithOrnaments.indexOf(graphicalStaffEntry) !== -1)) {
- this.staffEntriesWithOrnaments.push(graphicalStaffEntry);
- }
- }
- }
- }
- }
- }
- }
- }
- }
- private optimizeRestPlacement(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const page: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = page.MusicSystems.length; idx2 < len2; ++idx2) {
- const system: MusicSystem = page.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = system.StaffLines.length; idx3 < len3; ++idx3) {
- const line: StaffLine = system.StaffLines[idx3];
- for (let idx4: number = 0, len4: number = line.Measures.length; idx4 < len4; ++idx4) {
- const measure: GraphicalMeasure = line.Measures[idx4];
- for (let idx5: number = 0, len5: number = measure.staffEntries.length; idx5 < len5; ++idx5) {
- const graphicalStaffEntry: GraphicalStaffEntry = measure.staffEntries[idx5];
- this.optimizeRestNotePlacement(graphicalStaffEntry, measure);
- }
- }
- }
- }
- }
- }
- private calculateTwoRestNotesPlacementWithCollisionDetection(graphicalStaffEntry: GraphicalStaffEntry): void {
- const firstRestNote: GraphicalNote = graphicalStaffEntry.graphicalVoiceEntries[0].notes[0];
- const secondRestNote: GraphicalNote = graphicalStaffEntry.graphicalVoiceEntries[1].notes[0];
- secondRestNote.PositionAndShape.RelativePosition = new PointF2D(0.0, 2.5);
- graphicalStaffEntry.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement();
- firstRestNote.PositionAndShape.computeNonOverlappingPositionWithMargin(
- graphicalStaffEntry.PositionAndShape, ColDirEnum.Up,
- new PointF2D(0.0, secondRestNote.PositionAndShape.RelativePosition.y)
- );
- const relative: PointF2D = firstRestNote.PositionAndShape.RelativePosition;
- relative.y -= 1.0;
- firstRestNote.PositionAndShape.RelativePosition = relative;
- graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
- }
- private calculateRestNotePlacementWithCollisionDetectionFromGraphicalNote(graphicalStaffEntry: GraphicalStaffEntry): void {
- let restNote: GraphicalNote;
- let graphicalNotes: GraphicalNote[];
- if (graphicalStaffEntry.graphicalVoiceEntries[0].notes[0].sourceNote.Pitch === undefined) {
- restNote = graphicalStaffEntry.graphicalVoiceEntries[0].notes[0];
- graphicalNotes = graphicalStaffEntry.graphicalVoiceEntries[1].notes;
- } else {
- graphicalNotes = graphicalStaffEntry.graphicalVoiceEntries[0].notes;
- restNote = graphicalStaffEntry.graphicalVoiceEntries[1].notes[0];
- }
- let collision: boolean = false;
- graphicalStaffEntry.PositionAndShape.calculateAbsolutePositionsRecursiveWithoutTopelement();
- for (let idx: number = 0, len: number = graphicalNotes.length; idx < len; ++idx) {
- const graphicalNote: GraphicalNote = graphicalNotes[idx];
- if (restNote.PositionAndShape.marginCollisionDetection(graphicalNote.PositionAndShape)) {
- collision = true;
- break;
- }
- }
- if (collision) {
- if (restNote.sourceNote.ParentVoiceEntry.ParentVoice instanceof LinkedVoice) {
- const bottomBorder: number = graphicalNotes[0].PositionAndShape.BorderMarginBottom + graphicalNotes[0].PositionAndShape.RelativePosition.y;
- restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, bottomBorder - restNote.PositionAndShape.BorderMarginTop + 0.5);
- } else {
- const last: GraphicalNote = graphicalNotes[graphicalNotes.length - 1];
- const topBorder: number = last.PositionAndShape.BorderMarginTop + last.PositionAndShape.RelativePosition.y;
- if (graphicalNotes[0].sourceNote.ParentVoiceEntry.ParentVoice instanceof LinkedVoice) {
- restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, topBorder - restNote.PositionAndShape.BorderMarginBottom - 0.5);
- } else {
- const bottomBorder: number = graphicalNotes[0].PositionAndShape.BorderMarginBottom + graphicalNotes[0].PositionAndShape.RelativePosition.y;
- if (bottomBorder < 2.0) {
- restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, bottomBorder - restNote.PositionAndShape.BorderMarginTop + 0.5);
- } else {
- restNote.PositionAndShape.RelativePosition = new PointF2D(0.0, topBorder - restNote.PositionAndShape.BorderMarginBottom - 0.0);
- }
- }
- }
- }
- graphicalStaffEntry.PositionAndShape.calculateBoundingBox();
- }
- private calculateTieCurves(): void {
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- for (let idx4: number = 0, len5: number = staffLine.Measures.length; idx4 < len5; ++idx4) {
- const measure: GraphicalMeasure = staffLine.Measures[idx4];
- for (let idx6: number = 0, len6: number = measure.staffEntries.length; idx6 < len6; ++idx6) {
- const staffEntry: GraphicalStaffEntry = measure.staffEntries[idx6];
- const graphicalTies: GraphicalTie[] = staffEntry.GraphicalTies;
- for (let idx7: number = 0, len7: number = graphicalTies.length; idx7 < len7; ++idx7) {
- const graphicalTie: GraphicalTie = graphicalTies[idx7];
- if (graphicalTie.StartNote !== undefined && graphicalTie.StartNote.parentVoiceEntry.parentStaffEntry === staffEntry) {
- const tieIsAtSystemBreak: boolean = (
- graphicalTie.StartNote.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentStaffLine !==
- graphicalTie.EndNote.parentVoiceEntry.parentStaffEntry.parentMeasure.ParentStaffLine
- );
- this.layoutGraphicalTie(graphicalTie, tieIsAtSystemBreak);
- }
- }
- }
- }
- }
- }
- }
- }
- private calculateLyricsPosition(): void {
- const lyricStaffEntriesDict: Dictionary<StaffLine, GraphicalStaffEntry[]> = new Dictionary<StaffLine, GraphicalStaffEntry[]>();
- // sort the lyriceVerseNumbers for every Instrument that has Lyrics
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.ParentMusicSheet.Instruments.length; idx < len; ++idx) {
- const instrument: Instrument = this.graphicalMusicSheet.ParentMusicSheet.Instruments[idx];
- if (instrument.HasLyrics && instrument.LyricVersesNumbers.length > 0) {
- instrument.LyricVersesNumbers.sort();
- }
- }
- // first calc lyrics text positions
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- const lyricsStaffEntries: GraphicalStaffEntry[] =
- this.calculateSingleStaffLineLyricsPosition(staffLine, staffLine.ParentStaff.ParentInstrument.LyricVersesNumbers);
- lyricStaffEntriesDict.setValue(staffLine, lyricsStaffEntries);
- this.calculateLyricsExtendsAndDashes(lyricStaffEntriesDict.getValue(staffLine));
- }
- }
- }
- // then fill in the lyric word dashes and lyrics extends/underscores
- for (let idx: number = 0, len: number = this.graphicalMusicSheet.MusicPages.length; idx < len; ++idx) {
- const graphicalMusicPage: GraphicalMusicPage = this.graphicalMusicSheet.MusicPages[idx];
- for (let idx2: number = 0, len2: number = graphicalMusicPage.MusicSystems.length; idx2 < len2; ++idx2) {
- const musicSystem: MusicSystem = graphicalMusicPage.MusicSystems[idx2];
- for (let idx3: number = 0, len3: number = musicSystem.StaffLines.length; idx3 < len3; ++idx3) {
- const staffLine: StaffLine = musicSystem.StaffLines[idx3];
- this.calculateLyricsExtendsAndDashes(lyricStaffEntriesDict.getValue(staffLine));
- }
- }
- }
- }
- /**
- * This method calculates the dashes within the syllables of a LyricWord
- * @param lyricEntry
- */
- private calculateSingleLyricWord(lyricEntry: GraphicalLyricEntry): void {
- // const skyBottomLineCalculator: SkyBottomLineCalculator = new SkyBottomLineCalculator (this.rules);
- const graphicalLyricWord: GraphicalLyricWord = lyricEntry.ParentLyricWord;
- const index: number = graphicalLyricWord.GraphicalLyricsEntries.indexOf(lyricEntry);
- let nextLyricEntry: GraphicalLyricEntry = undefined;
- if (index >= 0) {
- nextLyricEntry = graphicalLyricWord.GraphicalLyricsEntries[index + 1];
- }
- if (nextLyricEntry === undefined) {
- return;
- }
- const startStaffLine: StaffLine = <StaffLine>lyricEntry.StaffEntryParent.parentMeasure.ParentStaffLine;
- const nextStaffLine: StaffLine = <StaffLine>nextLyricEntry.StaffEntryParent.parentMeasure.ParentStaffLine;
- const startStaffEntry: GraphicalStaffEntry = lyricEntry.StaffEntryParent;
- const endStaffentry: GraphicalStaffEntry = nextLyricEntry.StaffEntryParent;
- // if on the same StaffLine
- if (lyricEntry.StaffEntryParent.parentMeasure.ParentStaffLine === nextLyricEntry.StaffEntryParent.parentMeasure.ParentStaffLine) {
- // start- and End margins from the text Labels
- const startX: number = startStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- startStaffEntry.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.BorderMarginRight;
- const endX: number = endStaffentry.parentMeasure.PositionAndShape.RelativePosition.x +
- endStaffentry.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.x +
- nextLyricEntry.GraphicalLabel.PositionAndShape.BorderMarginLeft;
- const y: number = lyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.y;
- let numberOfDashes: number = 1;
- if ((endX - startX) > this.rules.MinimumDistanceBetweenDashes * 3) {
- // *3: need distance between word to first dash, dash to dash, dash to next word
- numberOfDashes = Math.floor((endX - startX) / this.rules.MinimumDistanceBetweenDashes) - 1;
- }
- // check distance and create the adequate number of Dashes
- if (numberOfDashes === 1) {
- // distance between the two GraphicalLyricEntries is big for only one Dash, position in the middle
- this.calculateSingleDashForLyricWord(startStaffLine, startX, endX, y);
- } else {
- // distance is big enough for more Dashes
- // calculate the adequate number of Dashes from the distance between the two LyricEntries
- // distance between the Dashes should be equal
- this.calculateDashes(startStaffLine, startX, endX, y);
- }
- } else {
- // start and end on different StaffLines
- // start margin from the text Label until the End of StaffLine
- const startX: number = startStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- startStaffEntry.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.BorderMarginRight;
- const lastGraphicalMeasure: GraphicalMeasure = startStaffLine.Measures[startStaffLine.Measures.length - 1];
- const endX: number = lastGraphicalMeasure.PositionAndShape.RelativePosition.x + lastGraphicalMeasure.PositionAndShape.Size.width;
- let y: number = lyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.y;
- // calculate Dashes for the first StaffLine
- this.calculateDashes(startStaffLine, startX, endX, y);
- // calculate Dashes for the second StaffLine (only if endStaffEntry isn't the first StaffEntry of the StaffLine)
- if (!(endStaffentry === endStaffentry.parentMeasure.staffEntries[0] &&
- endStaffentry.parentMeasure === endStaffentry.parentMeasure.ParentStaffLine.Measures[0])) {
- const secondStartX: number = nextStaffLine.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x;
- const secondEndX: number = endStaffentry.parentMeasure.PositionAndShape.RelativePosition.x +
- endStaffentry.PositionAndShape.RelativePosition.x +
- nextLyricEntry.GraphicalLabel.PositionAndShape.BorderMarginLeft;
- y = nextLyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.y;
- this.calculateDashes(nextStaffLine, secondStartX, secondEndX, y);
- }
- }
- }
- /**
- * This method calculates Dashes for a LyricWord.
- * @param staffLine
- * @param startX
- * @param endX
- * @param y
- */
- private calculateDashes(staffLine: StaffLine, startX: number, endX: number, y: number): void {
- let distance: number = endX - startX;
- if (distance < this.rules.MinimumDistanceBetweenDashes * 3) {
- this.calculateSingleDashForLyricWord(staffLine, startX, endX, y);
- } else {
- // enough distance for more Dashes
- const numberOfDashes: number = Math.floor(distance / this.rules.MinimumDistanceBetweenDashes) - 1;
- const distanceBetweenDashes: number = distance / (numberOfDashes + 1);
- let counter: number = 0;
- startX += distanceBetweenDashes;
- endX -= distanceBetweenDashes;
- while (counter <= Math.floor(numberOfDashes / 2.0) && endX > startX) {
- distance = this.calculateRightAndLeftDashesForLyricWord(staffLine, startX, endX, y);
- startX += distanceBetweenDashes;
- endX -= distanceBetweenDashes;
- counter++;
- }
- // if the remaining distance isn't big enough for two Dashes,
- // but long enough for a middle dash inbetween,
- // then put the last Dash in the middle of the remaining distance
- if (distance > distanceBetweenDashes * 2) {
- this.calculateSingleDashForLyricWord(staffLine, startX, endX, y);
- }
- }
- }
- /**
- * This method calculates a single Dash for a LyricWord, positioned in the middle of the given distance.
- * @param {StaffLine} staffLine
- * @param {number} startX
- * @param {number} endX
- * @param {number} y
- */
- private calculateSingleDashForLyricWord(staffLine: StaffLine, startX: number, endX: number, y: number): void {
- const dash: GraphicalLabel = new GraphicalLabel(new Label("-"), this.rules.LyricsHeight, TextAlignmentEnum.CenterBottom);
- dash.setLabelPositionAndShapeBorders();
- staffLine.LyricsDashes.push(dash);
- if (this.staffLinesWithLyricWords.indexOf(staffLine) === -1) {
- this.staffLinesWithLyricWords.push(staffLine);
- }
- dash.PositionAndShape.Parent = staffLine.PositionAndShape;
- const relative: PointF2D = new PointF2D(startX + (endX - startX) / 2, y);
- dash.PositionAndShape.RelativePosition = relative;
- }
- /**
- * Layouts the underscore line when a lyric entry is marked as extend
- * @param {GraphicalLyricEntry} lyricEntry
- */
- private calculateLyricExtend(lyricEntry: GraphicalLyricEntry): void {
- let startY: number = lyricEntry.GraphicalLabel.PositionAndShape.RelativePosition.y;
- const startStaffEntry: GraphicalStaffEntry = lyricEntry.StaffEntryParent;
- const startStaffLine: StaffLine = startStaffEntry.parentMeasure.ParentStaffLine;
- // find endstaffEntry and staffLine
- let endStaffEntry: GraphicalStaffEntry = undefined;
- let endStaffLine: StaffLine = undefined;
- const staffIndex: number = startStaffEntry.parentMeasure.ParentStaff.idInMusicSheet;
- for (let index: number = startStaffEntry.parentVerticalContainer.Index + 1;
- index < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
- ++index) {
- const gse: GraphicalStaffEntry = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[index].StaffEntries[staffIndex];
- if (gse === undefined) {
- continue;
- }
- if (gse.hasOnlyRests()) {
- break;
- }
- if (gse.LyricsEntries.length > 0) {
- break;
- }
- endStaffEntry = gse;
- endStaffLine = <StaffLine>endStaffEntry.parentMeasure.ParentStaffLine;
- }
- if (endStaffEntry === undefined) {
- return;
- }
- // if on the same StaffLine
- if (startStaffLine === endStaffLine) {
- // start- and End margins from the text Labels
- const startX: number = startStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- startStaffEntry.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.BorderMarginRight;
- // + startStaffLine.PositionAndShape.AbsolutePosition.x; // doesn't work, done in drawer
- const endX: number = endStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- endStaffEntry.PositionAndShape.RelativePosition.x +
- endStaffEntry.PositionAndShape.BorderMarginRight;
- // + endStaffLine.PositionAndShape.AbsolutePosition.x; // doesn't work, done in drawer
- // TODO maybe add half-width of following note.
- // though we don't have the vexflow note's bbox yet and extend layouting is unconstrained,
- // we have more room for spacing without it.
- // needed in order to line up with the Label's text bottom line (is the y position of the underscore)
- startY -= lyricEntry.GraphicalLabel.PositionAndShape.Size.height / 4;
- // create a Line (as underscore after the LyricLabel's End)
- this.calculateSingleLyricWordWithUnderscore(startStaffLine, startX, endX, startY);
- } else { // start and end on different StaffLines
- // start margin from the text Label until the End of StaffLine
- const lastMeasureBb: BoundingBox = startStaffLine.Measures[startStaffLine.Measures.length - 1].PositionAndShape;
- const startX: number = startStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- startStaffEntry.PositionAndShape.RelativePosition.x +
- lyricEntry.GraphicalLabel.PositionAndShape.BorderMarginRight;
- const endX: number = lastMeasureBb.RelativePosition.x +
- lastMeasureBb.Size.width;
- // needed in order to line up with the Label's text bottom line
- startY -= lyricEntry.GraphicalLabel.PositionAndShape.Size.height / 4;
- // first Underscore until the StaffLine's End
- this.calculateSingleLyricWordWithUnderscore(startStaffLine, startX, endX, startY);
- if (endStaffEntry === undefined) {
- return;
- }
- // second Underscore in the endStaffLine until endStaffEntry (if endStaffEntry isn't the first StaffEntry of the StaffLine))
- if (!(endStaffEntry === endStaffEntry.parentMeasure.staffEntries[0] &&
- endStaffEntry.parentMeasure === endStaffEntry.parentMeasure.ParentStaffLine.Measures[0])) {
- const secondStartX: number = endStaffLine.Measures[0].staffEntries[0].PositionAndShape.RelativePosition.x;
- const secondEndX: number = endStaffEntry.parentMeasure.PositionAndShape.RelativePosition.x +
- endStaffEntry.PositionAndShape.RelativePosition.x +
- endStaffEntry.PositionAndShape.BorderMarginRight;
- this.calculateSingleLyricWordWithUnderscore(endStaffLine, secondStartX, secondEndX, startY);
- }
- }
- }
- /**
- * This method calculates a single underscoreLine.
- * @param staffLine
- * @param startX
- * @param end
- * @param y
- */
- private calculateSingleLyricWordWithUnderscore(staffLine: StaffLine, startX: number, endX: number, y: number): void {
- const lineStart: PointF2D = new PointF2D(startX, y);
- const lineEnd: PointF2D = new PointF2D(endX, y);
- const graphicalLine: GraphicalLine = new GraphicalLine(lineStart, lineEnd, this.rules.LyricUnderscoreLineWidth);
- staffLine.LyricLines.push(graphicalLine);
- if (this.staffLinesWithLyricWords.indexOf(staffLine) === -1) {
- this.staffLinesWithLyricWords.push(staffLine);
- }
- }
- /**
- * This method calculates two Dashes for a LyricWord, positioned at the the two ends of the given distance.
- * @param {StaffLine} staffLine
- * @param {number} startX
- * @param {number} endX
- * @param {number} y
- * @returns {number}
- */
- private calculateRightAndLeftDashesForLyricWord(staffLine: StaffLine, startX: number, endX: number, y: number): number {
- const leftDash: GraphicalLabel = new GraphicalLabel(new Label("-"), this.rules.LyricsHeight, TextAlignmentEnum.CenterBottom);
- leftDash.setLabelPositionAndShapeBorders();
- staffLine.LyricsDashes.push(leftDash);
- if (this.staffLinesWithLyricWords.indexOf(staffLine) === -1) {
- this.staffLinesWithLyricWords.push(staffLine);
- }
- leftDash.PositionAndShape.Parent = staffLine.PositionAndShape;
- const leftDashRelative: PointF2D = new PointF2D(startX, y);
- leftDash.PositionAndShape.RelativePosition = leftDashRelative;
- const rightDash: GraphicalLabel = new GraphicalLabel(new Label("-"), this.rules.LyricsHeight, TextAlignmentEnum.CenterBottom);
- rightDash.setLabelPositionAndShapeBorders();
- staffLine.LyricsDashes.push(rightDash);
- rightDash.PositionAndShape.Parent = staffLine.PositionAndShape;
- const rightDashRelative: PointF2D = new PointF2D(endX, y);
- rightDash.PositionAndShape.RelativePosition = rightDashRelative;
- return (rightDash.PositionAndShape.RelativePosition.x - leftDash.PositionAndShape.RelativePosition.x);
- }
- private calculateDynamicExpressions(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
- for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
- if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
- for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
- if (sourceMeasure.StaffLinkedExpressions[j][k].InstantaneousDynamic !== undefined ||
- (sourceMeasure.StaffLinkedExpressions[j][k].StartingContinuousDynamic !== undefined &&
- sourceMeasure.StaffLinkedExpressions[j][k].StartingContinuousDynamic.StartMultiExpression ===
- sourceMeasure.StaffLinkedExpressions[j][k] && sourceMeasure.StaffLinkedExpressions[j][k].UnknownList.length === 0)
- ) {
- this.calculateDynamicExpressionsForMultiExpression(sourceMeasure.StaffLinkedExpressions[j][k], i, j);
- }
- }
- }
- }
- }
- }
- private calculateOctaveShifts(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
- for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
- if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
- for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
- if ((sourceMeasure.StaffLinkedExpressions[j][k].OctaveShiftStart !== undefined)) {
- this.calculateSingleOctaveShift(sourceMeasure, sourceMeasure.StaffLinkedExpressions[j][k], i, j);
- }
- }
- }
- }
- }
- }
- private getFirstLeftNotNullStaffEntryFromContainer(horizontalIndex: number, verticalIndex: number, multiStaffInstrument: boolean): GraphicalStaffEntry {
- if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex] !== undefined) {
- return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex];
- }
- for (let i: number = horizontalIndex - 1; i >= 0; i--) {
- if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex] !== undefined) {
- return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex];
- }
- }
- return undefined;
- }
- private getFirstRightNotNullStaffEntryFromContainer(horizontalIndex: number, verticalIndex: number, multiStaffInstrument: boolean): GraphicalStaffEntry {
- if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex] !== undefined) {
- return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[horizontalIndex].StaffEntries[verticalIndex];
- }
- for (let i: number = horizontalIndex + 1; i < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length; i++) {
- if (this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex] !== undefined) {
- return this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[i].StaffEntries[verticalIndex];
- }
- }
- return undefined;
- }
- private calculateWordRepetitionInstructions(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
- for (let idx: number = 0, len: number = sourceMeasure.FirstRepetitionInstructions.length; idx < len; ++idx) {
- const instruction: RepetitionInstruction = sourceMeasure.FirstRepetitionInstructions[idx];
- this.calculateWordRepetitionInstruction(instruction, i);
- }
- for (let idx: number = 0, len: number = sourceMeasure.LastRepetitionInstructions.length; idx < len; ++idx) {
- const instruction: RepetitionInstruction = sourceMeasure.LastRepetitionInstructions[idx];
- this.calculateWordRepetitionInstruction(instruction, i);
- }
- }
- }
- private calculateRepetitionEndings(): void {
- const musicsheet: MusicSheet = this.graphicalMusicSheet.ParentMusicSheet;
- for (let idx: number = 0, len: number = musicsheet.Repetitions.length; idx < len; ++idx) {
- const repetition: Repetition = musicsheet.Repetitions[idx];
- this.calcGraphicalRepetitionEndingsRecursively(repetition);
- }
- }
- private calculateTempoExpressions(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
- for (let j: number = 0; j < sourceMeasure.TempoExpressions.length; j++) {
- this.calculateTempoExpressionsForMultiTempoExpression(sourceMeasure, sourceMeasure.TempoExpressions[j], i);
- }
- }
- }
- private calculateMoodAndUnknownExpressions(): void {
- for (let i: number = 0; i < this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures.length; i++) {
- const sourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.SourceMeasures[i];
- for (let j: number = 0; j < sourceMeasure.StaffLinkedExpressions.length; j++) {
- if (this.graphicalMusicSheet.MeasureList[i][j].ParentStaff.ParentInstrument.Visible) {
- for (let k: number = 0; k < sourceMeasure.StaffLinkedExpressions[j].length; k++) {
- if ((sourceMeasure.StaffLinkedExpressions[j][k].MoodList.length > 0) ||
- (sourceMeasure.StaffLinkedExpressions[j][k].UnknownList.length > 0)) {
- this.calculateMoodAndUnknownExpression(sourceMeasure.StaffLinkedExpressions[j][k], i, j);
- }
- }
- }
- }
- }
- }
- /**
- * Calculates the desired stem direction depending on the number (or type) of voices.
- * If more than one voice is there, the main voice (typically the first or upper voice) will get stem up direction.
- * The others get stem down direction.
- * @param voiceEntry the voiceEntry for which the stem direction has to be calculated
- */
- private calculateStemDirectionFromVoices(voiceEntry: VoiceEntry): void {
- // Stem direction calculation:
- const hasLink: boolean = voiceEntry.ParentSourceStaffEntry.Link !== undefined;
- if (hasLink) {
- // in case of StaffEntryLink don't check mainVoice / linkedVoice
- if (voiceEntry === voiceEntry.ParentSourceStaffEntry.VoiceEntries[0]) {
- // set stem up:
- voiceEntry.WantedStemDirection = StemDirectionType.Up;
- return;
- } else {
- // set stem down:
- voiceEntry.WantedStemDirection = StemDirectionType.Down;
- return;
- }
- } else {
- if (voiceEntry.ParentVoice instanceof LinkedVoice) {
- // Linked voice: set stem down:
- voiceEntry.WantedStemDirection = StemDirectionType.Down;
- } else {
- // if this voiceEntry belongs to the mainVoice:
- // check first that there are also more voices present:
- if (voiceEntry.ParentSourceStaffEntry.VoiceEntries.length > 1) {
- // as this voiceEntry belongs to the mainVoice: stem Up
- voiceEntry.WantedStemDirection = StemDirectionType.Up;
- }
- }
- }
- // setBeamNotesWantedStemDirections() will be called at end of measure (createGraphicalMeasure)
- }
- /** Sets a voiceEntry's stem direction to one already set in other notes in its beam, if it has one. */
- private setBeamNotesWantedStemDirections(voiceEntry: VoiceEntry): void {
- if (voiceEntry.WantedStemDirection === StemDirectionType.Undefined &&
- voiceEntry.Notes.length > 0) {
- const beam: Beam = voiceEntry.Notes[0].NoteBeam;
- if (beam !== undefined) {
- // if there is a beam, find any already set stemDirection in the beam:
- for (const note of beam.Notes) {
- if (note.ParentVoiceEntry === voiceEntry) {
- continue;
- } else if (note.ParentVoiceEntry.WantedStemDirection !== StemDirectionType.Undefined) {
- // set the stem direction
- voiceEntry.WantedStemDirection = note.ParentVoiceEntry.WantedStemDirection;
- break;
- }
- }
- }
- }
- }
- }
|