Skip to content

Commit

Permalink
Metrics restructuring #2
Browse files Browse the repository at this point in the history
Completed chord classes and the following chord
components:
  stem, inputStem
  flag, inputFlag
  • Loading branch information
notator committed Jul 3, 2017
1 parent a392aa9 commit 35e7a74
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 60 deletions.
28 changes: 15 additions & 13 deletions Moritz.Symbols/Metrics/ChordMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private void SetStemAndFlags(ChordSymbol chord, List<HeadMetrics> topDownHeadsMe
|| durationClass == DurationClass.fourFlags
|| durationClass == DurationClass.fiveFlags)
{
_stemMetrics = NewStemMetrics(topDownHeadsMetrics, chord, _flagsBlockMetrics, stemThickness);
_stemMetrics = NewStemMetrics(topDownHeadsMetrics, chord, _flagsBlockMetrics, stemThickness, isInput);
}
}

Expand Down Expand Up @@ -1014,9 +1014,9 @@ public override void WriteSVG(SvgWriter w)
public void WriteSVG(SvgWriter w, bool isCautionary, bool isInput)
{
if(_stemMetrics != null)
_stemMetrics.WriteSVG(w, isInput);
_stemMetrics.WriteSVG(w);
if(_flagsBlockMetrics != null)
_flagsBlockMetrics.WriteSVG(w, isInput);
_flagsBlockMetrics.WriteSVG(w);
if(_headsMetricsTopDown != null)
{
foreach(HeadMetrics headMetrics in _headsMetricsTopDown)
Expand Down Expand Up @@ -1143,7 +1143,7 @@ public void MoveOuterStemTip(float stemTipY, VerticalDir stemDirection)
/// is too close to the noteheads in the other chord, the stem tip (and flagsBlock) is moved outwards.
/// FlagsBlockMetrics exist if the duration class is small enough, and the chord is not owned by a beamBlock.
/// </summary>
public void AdjustStemLengthAndFlagBlock(DurationClass thisDurationClass, float thisFontHeight, List<HeadMetrics> otherHeadsMetrics)
public void AdjustStemLengthAndFlagBlock(DurationClass thisDurationClass, float thisFontHeight, List<HeadMetrics> otherHeadsMetrics, bool isInput)
{
if(_stemMetrics == null
|| (_stemMetrics.VerticalDir == VerticalDir.up && BottomHeadMetrics.Bottom <= otherHeadsMetrics[0].Top)
Expand All @@ -1157,11 +1157,11 @@ public void AdjustStemLengthAndFlagBlock(DurationClass thisDurationClass, float
thisFontHeight,
_stemMetrics.VerticalDir,
_stemMetrics.StrokeWidth,
false);
isInput);

StemMetrics dummyStemMetrics =
DummyStemMetrics(otherHeadsMetrics, _stemMetrics.VerticalDir, thisFontHeight,
dummyFlagsBlockMetrics, null, _stemMetrics.StrokeWidth);
dummyFlagsBlockMetrics, null, _stemMetrics.StrokeWidth, isInput);

if(_stemMetrics.VerticalDir == VerticalDir.up)
{
Expand All @@ -1184,7 +1184,7 @@ public void AdjustStemLengthAndFlagBlock(DurationClass thisDurationClass, float
{
StemMetrics dummyStemMetrics =
DummyStemMetrics(otherHeadsMetrics, _stemMetrics.VerticalDir, thisFontHeight, null, null,
_stemMetrics.StrokeWidth);
_stemMetrics.StrokeWidth, isInput);

if(_stemMetrics.VerticalDir == VerticalDir.up)
{
Expand Down Expand Up @@ -1246,9 +1246,9 @@ public void MoveAuxilliariesToLyricHeight(VerticalDir voiceStemDirection, float
/// <summary>
/// Sets the stem. Pass flagsBlockMetrics=null for duration classes having no flags.
/// </summary>
private StemMetrics NewStemMetrics(List<HeadMetrics> topDownHeadsMetrics, ChordSymbol chord, Metrics flagsBlockMetrics, float strokeWidth)
private StemMetrics NewStemMetrics(List<HeadMetrics> topDownHeadsMetrics, ChordSymbol chord, Metrics flagsBlockMetrics, float strokeWidth, bool isInput)
{
return NewStemMetrics(topDownHeadsMetrics, chord.Stem.Direction, chord.FontHeight, flagsBlockMetrics, chord.BeamBlock, strokeWidth);
return NewStemMetrics(topDownHeadsMetrics, chord.Stem.Direction, chord.FontHeight, flagsBlockMetrics, chord.BeamBlock, strokeWidth, isInput);
}

private StemMetrics NewStemMetrics(
Expand All @@ -1257,7 +1257,8 @@ private StemMetrics NewStemMetrics(
float fontHeight,
Metrics flagsBlockMetrics,
BeamBlock beamBlock,
float strokeWidth)
float strokeWidth,
bool isInput)
{
HeadMetrics outerNotehead = FindOuterNotehead(topDownHeadsMetrics, stemDirection);
HeadMetrics innerNotehead = FindInnerNotehead(topDownHeadsMetrics, stemDirection);
Expand Down Expand Up @@ -1319,7 +1320,7 @@ private StemMetrics NewStemMetrics(
}
}

StemMetrics stemMetrics = new StemMetrics(top, x, bottom, strokeWidth, stemDirection);
StemMetrics stemMetrics = new StemMetrics(top, x, bottom, strokeWidth, stemDirection, isInput);
return stemMetrics;
}

Expand All @@ -1333,7 +1334,8 @@ private StemMetrics DummyStemMetrics(
float fontHeight,
Metrics flagsBlockMetrics,
BeamBlock beamBlock,
float strokeWidth)
float strokeWidth,
bool isInput)
{
List<HeadMetrics> tempTopDownHeadsMetrics = new List<HeadMetrics>();
foreach(HeadMetrics headMetrics in otherChordTopDownHeadsMetrics)
Expand All @@ -1342,7 +1344,7 @@ private StemMetrics DummyStemMetrics(
tempTopDownHeadsMetrics.Add(newHeadMetrics);
}

return NewStemMetrics(tempTopDownHeadsMetrics, stemDirection, fontHeight, flagsBlockMetrics, beamBlock, strokeWidth);
return NewStemMetrics(tempTopDownHeadsMetrics, stemDirection, fontHeight, flagsBlockMetrics, beamBlock, strokeWidth, isInput);
}

public BeamBlock BeamBlock = null;
Expand Down
11 changes: 2 additions & 9 deletions Moritz.Symbols/Metrics/FlagsBlockMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FlagsBlockMetrics : Metrics
/// Should be called with a duration class having a flag block
/// </summary>
public FlagsBlockMetrics(DurationClass durationClass, float fontHeight, VerticalDir stemDirection, bool isInput)
: base(CSSClass.flag)
: base(isInput ? CSSClass.inputFlag : CSSClass.flag)
{
_left = 0F;
_right = 0.31809F * fontHeight;
Expand Down Expand Up @@ -87,14 +87,7 @@ public static void ClearUsedFlagIDsList()
}

public override void WriteSVG(SvgWriter w)
{
throw new NotImplementedException();
}

public void WriteSVG(SvgWriter w, bool isInput)
{
CSSClass flagClass = isInput ? CSSClass.inputFlag : CSSClass.flag;

{
string flagIDString = _flagID.ToString();

if(flagIDString.Contains("ight")) // stemDirection is up
Expand Down
13 changes: 3 additions & 10 deletions Moritz.Symbols/Metrics/Metrics_Lines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public override void WriteSVG(SvgWriter w)

internal class StemMetrics : LineStyle
{
public StemMetrics(float top, float x, float bottom, float strokeWidth, VerticalDir verticalDir)
: base(CSSClass.stem, strokeWidth, "black")
public StemMetrics(float top, float x, float bottom, float strokeWidth, VerticalDir verticalDir, bool isInput)
: base(isInput ? CSSClass.inputStem : CSSClass.stem, strokeWidth, "black")
{
_originX = x;
_originY = top;
Expand All @@ -60,14 +60,7 @@ public StemMetrics(float top, float x, float bottom, float strokeWidth, Vertical

public override void WriteSVG(SvgWriter w)
{
throw new NotImplementedException();
}

public void WriteSVG(SvgWriter w, bool isInput)
{
CSSClass stemClass = isInput ? CSSClass.inputStem : CSSClass.stem;

w.SvgLine(stemClass, _originX, _top, _originX, _bottom);
w.SvgLine(CSSClass, _originX, _top, _originX, _bottom);
}

public object Clone()
Expand Down
16 changes: 10 additions & 6 deletions Moritz.Symbols/Metrics/StandardSymbolSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ public override Metrics NoteObjectMetrics(Graphics graphics, NoteObject noteObje
Barline barline = noteObject as Barline;
CautionaryOutputChordSymbol cautionaryOutputChordSymbol = noteObject as CautionaryOutputChordSymbol;
CautionaryInputChordSymbol cautionaryInputChordSymbol = noteObject as CautionaryInputChordSymbol;
ChordSymbol chord = noteObject as ChordSymbol;
ChordSymbol chordSymbol = noteObject as ChordSymbol;
InputChordSymbol inputChordSymbol = noteObject as InputChordSymbol;
RestSymbol rest = noteObject as RestSymbol;
if(barline != null)
{
Expand All @@ -243,18 +244,21 @@ public override Metrics NoteObjectMetrics(Graphics graphics, NoteObject noteObje
returnMetrics = new ClefMetrics(clef, gap, cssClass, clefID);
}
}
else if(cautionaryInputChordSymbol != null)
{
returnMetrics = new ChordMetrics(graphics, cautionaryInputChordSymbol, voiceStemDirection, gap, strokeWidth, CSSClass.cautionaryInputChord);
}
else if(cautionaryOutputChordSymbol != null)
{

returnMetrics = new ChordMetrics(graphics, cautionaryOutputChordSymbol, voiceStemDirection, gap, strokeWidth, CSSClass.cautionaryChord);
}
else if(cautionaryInputChordSymbol != null)
else if(inputChordSymbol != null)
{
returnMetrics = new ChordMetrics(graphics, cautionaryInputChordSymbol, voiceStemDirection, gap, strokeWidth, CSSClass.cautionaryInputChord);
returnMetrics = new ChordMetrics(graphics, inputChordSymbol, voiceStemDirection, gap, strokeWidth, CSSClass.inputChord);
}
else if(chord != null)
else if(chordSymbol != null)
{
returnMetrics = new ChordMetrics(graphics, chord, voiceStemDirection, gap, strokeWidth, CSSClass.chord);
returnMetrics = new ChordMetrics(graphics, chordSymbol, voiceStemDirection, gap, strokeWidth, CSSClass.chord);
}
else if(rest != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
{
if(Visible && staffIsVisible)
{
w.SvgStartGroup("cautionaryChord");
w.SvgStartGroup(ChordMetrics.CSSClass.ToString()); // "cautionaryInputChord"
w.SvgStartGroup(null);

this.ChordMetrics.WriteSVG(w, true, true);
Expand All @@ -36,7 +36,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("cautionaryChord ");
sb.Append("cautionaryInputChord ");
sb.Append(InfoString);
return sb.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
{
if(Visible && staffIsVisible)
{
w.SvgStartGroup("cautionaryChord");
w.SvgStartGroup(ChordMetrics.CSSClass.ToString()); // "cautionaryChord"
w.SvgStartGroup(null);

this.ChordMetrics.WriteSVG(w, true, false);
Expand All @@ -35,7 +35,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("cautionaryChord ");
sb.Append("cautionaryOutputChord ");
sb.Append(InfoString);
return sb.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
if(ChordMetrics.BeamBlock != null)
ChordMetrics.BeamBlock.WriteSVG(w, true);

w.SvgStartGroup("inputChord");
w.SvgStartGroup(ChordMetrics.CSSClass.ToString()); // "inputChord";

Debug.Assert(_msDuration > 0);

Expand All @@ -116,7 +116,7 @@ public override void WriteSVG(SvgWriter w, bool staffIsVisible)
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("input chord ");
sb.Append("inputChord ");
sb.Append(InfoString);
return sb.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void WriteSVG(SvgWriter w, bool staffIsVisible, int channel, CarryMsgs ca
if(staffIsVisible && ChordMetrics.BeamBlock != null)
ChordMetrics.BeamBlock.WriteSVG(w, false);

w.SvgStartGroup(ChordMetrics.CSSClass.ToString()); // "chord" or "inputChord");
w.SvgStartGroup(ChordMetrics.CSSClass.ToString()); // "chord";
if(staffIsVisible)
{
w.WriteAttributeString("score", "alignment", null, ChordMetrics.OriginX.ToString(M.En_USNumberFormat));
Expand All @@ -175,7 +175,7 @@ public void WriteSVG(SvgWriter w, bool staffIsVisible, int channel, CarryMsgs ca
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("output chord ");
sb.Append("outputChord ");
sb.Append(InfoString);
return sb.ToString();
}
Expand Down
8 changes: 4 additions & 4 deletions Moritz.Symbols/System Components/Staff Components/Voice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ public virtual void WriteSVG(SvgWriter w, bool staffIsVisible, List<CarryMsgs> c
{
inputChordSymbol.WriteSVG(w, staffIsVisible);
}
else if(inputRestSymbol != null)
{
inputRestSymbol.WriteSVG(w, staffIsVisible);
}
else if(cautionaryOutputChordSymbol != null)
{
cautionaryOutputChordSymbol.WriteSVG(w, staffIsVisible);
Expand All @@ -81,6 +77,10 @@ public virtual void WriteSVG(SvgWriter w, bool staffIsVisible, List<CarryMsgs> c
Debug.Assert(carryMsgsPerChannel != null);
outputChordSymbol.WriteSVG(w, staffIsVisible, this.MidiChannel, carryMsgsPerChannel[this.MidiChannel]);
}
else if(inputRestSymbol != null)
{
inputRestSymbol.WriteSVG(w, staffIsVisible);
}
else if(outputRestSymbol != null)
{
Debug.Assert(carryMsgsPerChannel != null);
Expand Down
7 changes: 4 additions & 3 deletions Moritz.Symbols/System Components/Staff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ public void AdjustTwoPartChords()

private void AdjustStemLengths(ChordSymbol upperChord, ChordSymbol lowerChord)
{
upperChord.ChordMetrics.AdjustStemLengthAndFlagBlock(upperChord.DurationClass, upperChord.FontHeight, lowerChord.ChordMetrics.HeadsMetrics);
lowerChord.ChordMetrics.AdjustStemLengthAndFlagBlock(lowerChord.DurationClass, lowerChord.FontHeight, upperChord.ChordMetrics.HeadsMetrics);
bool isInput = (upperChord is InputChordSymbol);
upperChord.ChordMetrics.AdjustStemLengthAndFlagBlock(upperChord.DurationClass, upperChord.FontHeight, lowerChord.ChordMetrics.HeadsMetrics, isInput);
lowerChord.ChordMetrics.AdjustStemLengthAndFlagBlock(lowerChord.DurationClass, lowerChord.FontHeight, upperChord.ChordMetrics.HeadsMetrics, isInput);
}

/// <summary>
Expand Down Expand Up @@ -493,7 +494,7 @@ public void AdjustBeamedStemHeights(int voiceIndex)
{
foreach(ChordSymbol otherChord in enclosedChords)
{
chord.ChordMetrics.AdjustStemLengthAndFlagBlock(chord.DurationClass, chord.FontHeight, otherChord.ChordMetrics.HeadsMetrics);
chord.ChordMetrics.AdjustStemLengthAndFlagBlock(chord.DurationClass, chord.FontHeight, otherChord.ChordMetrics.HeadsMetrics, (chord is InputChordSymbol));
}
}
if(adjustVoiceIndex == 0)
Expand Down
25 changes: 18 additions & 7 deletions Moritz.Xml/CSSClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,28 @@ public enum CSSClass
inputOpaqueBeam, // TODO
#endregion

chord, inputChord, cautionaryChord, cautionaryInputChord,
//-------------------------------------------
#region recorded and used 03.07.2017
#region chord classes
chord,
inputChord,
cautionaryChord,
cautionaryInputChord,
#endregion chord classes
#region chord components
stem, inputStem,
// flags and inputFlags whose ID (e.g. "inputLeft3Flags") has been recorded will be written to the defs.
// Neither needs a CSS definition because they use path's default settings.
flag, inputFlag,

#endregion chord components
#endregion recorded and used 03.07.2017
//===========================================
#region chord components
notehead, // Used, recorded.
inputNotehead, // written, recorded, not yet defined
accidental, // Used, recorded.
inputAccidental,// written, recorded, not yet defined
stem, // Used, recorded, defined.
inputStem, // written, not recorded, not defined
rest, // Used, recorded.
inputRest, // written, recorded, not yet defined
dynamic, // Used, recorded.
Expand All @@ -80,10 +94,7 @@ public enum CSSClass
inputLedgerline, // written, not recorded, not defined
// Flags whose ID (e.g. "left3Flags") appears in the MetricsForUse.UsedIDs list will be written to the defs.
// Flag does not need a CSS definition because it uses path's default settings.
flag, // written and recorded
// inputFlags whose ID (e.g. "inputLeft3Flags") appears in the MetricsForUse.UsedIDs list will be written to the defs.
// inputFlags does not need a CSS definition because it uses path's default settings.
inputFlag, // written and recorded.

ornament, // Used, recorded.
noteExtender, // Used, recorded, defined.
cautionaryBracket, // Used, recorded, defined.
Expand Down

0 comments on commit 35e7a74

Please sign in to comment.