private List<float> GetX2sFromChord2(List<float> ys, ChordMetrics chord2Metrics, float hairlinePadding) { List<float> x2s = new List<float>(); LedgerlineBlockMetrics c2UpperLedgerlineMetrics = chord2Metrics.UpperLedgerlineBlockMetrics; LedgerlineBlockMetrics c2LowerLedgerlineMetrics = chord2Metrics.LowerLedgerlineBlockMetrics; List<HeadMetrics> c2headsMetrics = chord2Metrics.HeadsMetrics; Debug.Assert(c2headsMetrics.Count > 0); List<AccidentalMetrics> c2AccidentalsMetrics = chord2Metrics.TopDownAccidentalsMetrics; float verticalPadding = hairlinePadding * 4.0f; foreach(float y in ys) { float x2 = float.MaxValue; if(c2UpperLedgerlineMetrics != null) { if(y >= (c2UpperLedgerlineMetrics.Top - verticalPadding) && y <= (c2UpperLedgerlineMetrics.Bottom + verticalPadding)) x2 = x2 < c2UpperLedgerlineMetrics.Left ? x2 : c2UpperLedgerlineMetrics.Left; } if(c2LowerLedgerlineMetrics != null) { if(y >= (c2LowerLedgerlineMetrics.Top - verticalPadding) && y <= (c2LowerLedgerlineMetrics.Bottom + verticalPadding)) x2 = x2 < c2LowerLedgerlineMetrics.Left ? x2 : c2LowerLedgerlineMetrics.Left; } foreach(HeadMetrics headMetrics in c2headsMetrics) { if(y >= (headMetrics.Top - verticalPadding) && y <= (headMetrics.Bottom + verticalPadding)) x2 = x2 < headMetrics.Left ? x2 : headMetrics.Left; } foreach(AccidentalMetrics accidentalMetrics in c2AccidentalsMetrics) { if(y >= (accidentalMetrics.Top - verticalPadding) && y <= (accidentalMetrics.Bottom + verticalPadding)) x2 = x2 < accidentalMetrics.Left ? x2 : accidentalMetrics.Left; } x2 = x2 < float.MaxValue ? x2 : chord2Metrics.Left; x2s.Add(x2 - hairlinePadding); } float minX = float.MaxValue; foreach(float x in x2s) { minX = minX < x ? minX : x; } List<float> x2sMinimum = new List<float>(); foreach(float x in x2s) x2sMinimum.Add(minX); return x2sMinimum; }
public override Metrics NoteObjectMetrics(Graphics graphics, NoteObject noteObject, VerticalDir voiceStemDirection, float gap, float strokeWidth) { Metrics returnMetrics = null; ClefSymbol clef = noteObject as ClefSymbol; Barline barline = noteObject as Barline; CautionaryOutputChordSymbol cautionaryOutputChordSymbol = noteObject as CautionaryOutputChordSymbol; CautionaryInputChordSymbol cautionaryInputChordSymbol = noteObject as CautionaryInputChordSymbol; ChordSymbol chord = noteObject as ChordSymbol; RestSymbol rest = noteObject as RestSymbol; if(barline != null) { returnMetrics = new BarlineMetrics(graphics, barline, gap); } else if(clef != null) { if(clef.ClefType != "n") returnMetrics = new ClefMetrics(clef, gap); } else if(cautionaryOutputChordSymbol != null) { returnMetrics = new ChordMetrics(graphics, cautionaryOutputChordSymbol, voiceStemDirection, gap, strokeWidth); } else if(cautionaryInputChordSymbol != null) { returnMetrics = new ChordMetrics(graphics, cautionaryInputChordSymbol, voiceStemDirection, gap, strokeWidth); } else if(chord != null) { returnMetrics = new ChordMetrics(graphics, chord, voiceStemDirection, gap, strokeWidth); } else if(rest != null) { // All rests are originally created on the centre line. // They are moved vertically later, if they are on a 2-Voice staff. returnMetrics = new RestMetrics(graphics, rest, gap, noteObject.Voice.Staff.NumberOfStafflines, strokeWidth); } return returnMetrics; }
private List<float> GetX1sFromChord1(ChordMetrics chord1Metrics, float hairlinePadding) { List<float> x1s = new List<float>(); LedgerlineBlockMetrics upperLedgerlineMetrics = chord1Metrics.UpperLedgerlineBlockMetrics; LedgerlineBlockMetrics lowerLedgerlineMetrics = chord1Metrics.LowerLedgerlineBlockMetrics; List<HeadMetrics> headsMetrics = chord1Metrics.HeadsMetrics; Debug.Assert(headsMetrics.Count > 0); foreach(HeadMetrics headmetrics in headsMetrics) { float x1 = headmetrics.Right; if(upperLedgerlineMetrics != null && headmetrics.OriginY >= upperLedgerlineMetrics.Top && headmetrics.OriginY <= upperLedgerlineMetrics.Bottom) x1 = upperLedgerlineMetrics.Right; if(lowerLedgerlineMetrics != null && headmetrics.OriginY >= lowerLedgerlineMetrics.Top && headmetrics.OriginY <= lowerLedgerlineMetrics.Bottom) x1 = lowerLedgerlineMetrics.Right; x1s.Add(x1 + hairlinePadding); } return x1s; }
/// <summary> /// This chordMetrics is in the lower of two voices on a staff, and there is a synchronous chordMetrics (the 1st argument) /// at the same MsPosition on the same staff. Both chordSymbols have Metrics, and the chord in the lower voice has /// been moved (either left or right) with all its accidentals, ledgerlines etc. so that there are no collisions between /// noteheads. /// </summary> public void AdjustAccidentalsForTwoChords(ChordMetrics otherChordMetrics, float staffLineStemStrokeWidth) { // first adjust the accidentals in the rightmost chord so that they are left of the other chord ChordMetrics leftChordMetrics = null; ChordMetrics rightChordMetrics = null; #region get left and right ChordMetrics if(this.OriginX < otherChordMetrics.OriginX) { leftChordMetrics = this; rightChordMetrics = otherChordMetrics; } else { leftChordMetrics = otherChordMetrics; rightChordMetrics = this; } #endregion #region get top and bottom ledgerlineBlocks (can be null) LedgerlineBlockMetrics upperLedgerlineBlockMetrics = CombinedLedgerlineBlockMetrics(_upperLedgerlineBlockMetrics, otherChordMetrics.UpperLedgerlineBlockMetrics, staffLineStemStrokeWidth); LedgerlineBlockMetrics lowerLedgerlineBlockMetrics = CombinedLedgerlineBlockMetrics(_lowerLedgerlineBlockMetrics, otherChordMetrics.LowerLedgerlineBlockMetrics, staffLineStemStrokeWidth); #endregion List<AccidentalMetrics> existingAccidentalsMetrics = new List<AccidentalMetrics>(); List<HeadMetrics> combinedHeadMetrics = AllHeadsTopDown(leftChordMetrics.HeadsMetrics, rightChordMetrics.HeadsMetrics); List<AccidentalMetrics> leftChordAccidentalsMetrics = leftChordMetrics.AccidentalsMetrics; List<AccidentalMetrics> rightChordAccidentalsMetrics = rightChordMetrics.AccidentalsMetrics; List<AccidentalMetrics> combinedAccidentalMetrics = AllAccidentalsTopDown(leftChordAccidentalsMetrics, rightChordAccidentalsMetrics); foreach(AccidentalMetrics accidentalMetrics in combinedAccidentalMetrics) // these are cloned accidentalsMetrics { if(leftChordAccidentalsMetrics.Contains(accidentalMetrics)) { leftChordMetrics.MoveAccidentalLeft(accidentalMetrics, combinedHeadMetrics, leftChordMetrics.StemMetrics, upperLedgerlineBlockMetrics, lowerLedgerlineBlockMetrics, existingAccidentalsMetrics); /// accidentalMetrics is a clone of the original one contained in the ChordMetrics. /// Now move the real accidental to the new position. leftChordMetrics.SetAccidentalXPos(accidentalMetrics); } else { rightChordMetrics.MoveAccidentalLeft(accidentalMetrics, combinedHeadMetrics, leftChordMetrics.StemMetrics, upperLedgerlineBlockMetrics, lowerLedgerlineBlockMetrics, existingAccidentalsMetrics); rightChordMetrics.SetAccidentalXPos(accidentalMetrics); } existingAccidentalsMetrics.Add(accidentalMetrics); } }