public void Execute() { ActualResult = MarkUtils.AutoBarrePosition(marks, barreTypeOption, rightToLeft); Assert.AreEqual(ExpectedResult, ActualResult); }
public Diagram ToDiagram(ChordFinderStyle chordFinderStyle) { int[] marks = MarkUtils.AbsoluteToRelativeMarks(Marks, out int baseLine, Parent.ChordFinderOptions.NumFrets); InternalNote?[] notes = MarkUtils.GetInternalNotes(Marks, Parent.ChordFinderOptions.Tuning); InternalNote rootNote = NoteUtils.ToInternalNote(Parent.ChordFinderOptions.RootNote); if (chordFinderStyle.MirrorResults) { Array.Reverse(marks); Array.Reverse(notes); } int numStrings = marks.Length; int numFrets = Parent.ChordFinderOptions.NumFrets; Diagram d = new Diagram(chordFinderStyle.Style, numStrings, numFrets); if (chordFinderStyle.AddTitle) { d.Title = NoteUtils.ToString(Parent.ChordFinderOptions.RootNote) + Parent.ChordFinderOptions.ChordQuality.Abbreviation; d.Style.TitleLabelStyle = DiagramLabelStyle.ChordName; } // Add marks for (int i = 0; i < marks.Length; i++) { int @string = i + 1; int fret = Math.Max(marks[i], 0); MarkPosition mp = new MarkPosition(@string, fret); DiagramMark dm = d.NewMark(mp); // Set mark type if (marks[i] == -1) // Muted string { dm.Type = DiagramMarkType.Muted; } else if (marks[i] == 0) // Open string { dm.Type = DiagramMarkType.Open; } // Change to root if necessary if (chordFinderStyle.AddRootNotes && notes[i].HasValue && notes[i].Value == rootNote) { dm.Type = (dm.Type == DiagramMarkType.Open) ? DiagramMarkType.OpenRoot : DiagramMarkType.Root; } // Add text if (chordFinderStyle.MarkTextOption != MarkTextOption.None) { dm.Text = GetText(notes, i, chordFinderStyle.MarkTextOption); } // Add bottom marks if (chordFinderStyle.AddBottomMarks) { MarkPosition bottomPosition = new MarkPosition(@string, numFrets + 1); DiagramMark bottomMark = d.NewMark(bottomPosition); bottomMark.Type = DiagramMarkType.Bottom; bottomMark.Text = GetText(notes, i, chordFinderStyle.BottomMarkTextOption); } } // Add nut or fret label if (baseLine == 0) { d.Style.GridNutVisible = true; } else { d.Style.GridNutVisible = false; FretLabelPosition flp = new FretLabelPosition(chordFinderStyle.FretLabelSide, 1); d.NewFretLabel(flp, baseLine.ToString()); } // Add barre BarrePosition bp = MarkUtils.AutoBarrePosition(marks, chordFinderStyle.BarreTypeOption, chordFinderStyle.MirrorResults); if (null != bp) { d.NewBarre(bp); } return(d); }
public void AutoBarrePosition_NullTest() { Assert.IsNull(MarkUtils.AutoBarrePosition(null)); }
internal static Diagram GetDiagram(Chord chord, ChordOptions chordOptions, DiagramStyle parentStyle) { if (null == chord) { throw new ArgumentNullException(nameof(chord)); } if (null == chordOptions) { throw new ArgumentNullException(nameof(chordOptions)); } if (null == parentStyle) { throw new ArgumentNullException(nameof(parentStyle)); } Diagram diagram = new Diagram(parentStyle, chord.NumStrings, chord.NumFrets); // Setup base diagram.Style.Orientation = DiagramOrientation.UpDown; diagram.Style.LabelLayoutModel = DiagramLabelLayoutModel.AddPaddingVertical; diagram.Style.DiagramColor = "White"; diagram.Style.DiagramOpacity = 0; diagram.Style.DiagramBorderColor = "Black"; diagram.Style.DiagramBorderThickness = 0; // Process title diagram.Title = chord.Title; diagram.Style.TitleLabelStyle = DiagramLabelStyle.ChordName; diagram.Style.TitleTextSize = chordOptions.FontSize * (19.0 / 24.0); diagram.Style.TitleVisible = true; diagram.Style.TitleTextSizeModRatio = 0.75; diagram.Style.TitleGridPadding = diagram.Style.TitleTextSize / 2.0; diagram.Style.TitleFontFamily = chordOptions.FontFamily; diagram.Style.TitleColor = "Black"; diagram.Style.TitleOpacity = 1; diagram.Style.TitleTextAlignment = DiagramHorizontalAlignment.Center; // Process grid double margin = chordOptions.Margin; diagram.Style.GridMargin = margin; diagram.Style.GridMarginLeft = margin; diagram.Style.GridMarginRight = margin; diagram.Style.GridMarginTop = margin; diagram.Style.GridMarginBottom = margin; double titleHeight = diagram.Style.TitleTextSize; double rectWidth = chordOptions.Width - (2.0 * chordOptions.Margin); double rectHeight = chordOptions.Height - titleHeight - (2.0 * chordOptions.Margin); diagram.Style.GridLineThickness = chordOptions.StrokeWidth; diagram.Style.GridStringSpacing = rectWidth / (chord.NumStrings - 1); diagram.Style.GridFretSpacing = rectHeight / chord.NumFrets; diagram.Style.GridLineColor = "White"; diagram.Style.GridOpacity = 0; diagram.Style.GridLineColor = "Black"; DiagramTextStyle titleTextStyle = DiagramTextStyle.Regular; switch (chordOptions.FontStyle) { case FontStyle.Bold: titleTextStyle = DiagramTextStyle.Bold; break; case FontStyle.Italic: titleTextStyle = DiagramTextStyle.Italic; break; case FontStyle.BoldItalic: titleTextStyle = DiagramTextStyle.BoldItalic; break; } diagram.Style.TitleTextStyle = titleTextStyle; // Process marks DiagramMarkStyleWrapper dmsw = new DiagramMarkStyleWrapper(diagram.Style); dmsw.MarkType = DiagramMarkType.Normal; dmsw.MarkVisible = true; dmsw.MarkRadiusRatio = 0.67; dmsw.MarkShape = DiagramMarkShape.Circle; dmsw.MarkBorderThickness = 2; dmsw.MarkColor = "Black"; dmsw.MarkOpacity = 1.0; dmsw.MarkBorderColor = "Black"; dmsw.MarkType = DiagramMarkType.Muted; dmsw.MarkVisible = true; dmsw.MarkRadiusRatio = 0.33; dmsw.MarkShape = DiagramMarkShape.X; dmsw.MarkBorderThickness = 2; dmsw.MarkColor = "Black"; dmsw.MarkOpacity = 1.0; dmsw.MarkBorderColor = "Black"; dmsw.MarkType = DiagramMarkType.Open; bool openCircle = (chordOptions.OpenStringType == OpenStringType.Circle); dmsw.MarkVisible = openCircle; dmsw.MarkRadiusRatio = 0.33; dmsw.MarkShape = openCircle ? DiagramMarkShape.Circle : DiagramMarkShape.None; dmsw.MarkBorderThickness = 2; dmsw.MarkColor = "White"; dmsw.MarkOpacity = 1.0; dmsw.MarkBorderColor = "Black"; for (int str = 0; str < chord.Marks.Length; str++) { int fret = chord.Marks[str]; MarkPosition mp = new MarkPosition(str + 1, Math.Max(fret, 0)); if (fret == -1) { DiagramMark mutedMark = diagram.NewMark(mp); mutedMark.Type = DiagramMarkType.Muted; } else if (fret == 0 && openCircle) { DiagramMark openMark = diagram.NewMark(mp); openMark.Type = DiagramMarkType.Open; } else if (fret > 0) { diagram.NewMark(mp); } } diagram.Style.BarreVisible = true; diagram.Style.BarreVerticalAlignment = DiagramVerticalAlignment.Middle; diagram.Style.BarreArcRatio = 0.5; diagram.Style.BarreStack = DiagramBarreStack.UnderMarks; diagram.Style.BarreOpacity = 1.0; diagram.Style.BarreLineColor = "Black"; diagram.Style.BarreLineThickness = 2.0; // Process barres if (chordOptions.BarreType == BarreType.None) { diagram.Style.BarreVisible = false; } BarrePosition bp = MarkUtils.AutoBarrePosition(chord.Marks); if (chord.Barre == -1) { if (chordOptions.FullBarres && null != bp) { bp = new BarrePosition(bp.Fret, 1, chord.NumStrings); } } else if (chord.Barre == 0) { bp = null; } else if (chord.Barre > 0) { if (null != bp) { if (chordOptions.FullBarres) { bp = new BarrePosition(bp.Fret, 1, chord.NumStrings); } else { bp = new BarrePosition(chord.Barre, bp.StartString, bp.EndString); } } } if (chordOptions.FullBarres && null != bp) { bp = new BarrePosition(bp.Fret, 1, chord.NumStrings); } if (null != bp) { if (chordOptions.BarreType == BarreType.Straight) { DiagramBarre straightBarre = diagram.NewBarre(bp); straightBarre.Style.BarreArcRatio = 0; } else if (chordOptions.BarreType == BarreType.Arc) { diagram.NewBarre(bp); } } // Process baseline / fret marker diagram.Style.GridNutVisible = false; diagram.Style.GridNutRatio = 2.0; diagram.Style.FretLabelTextVisible = true; diagram.Style.FretLabelTextAlignment = DiagramHorizontalAlignment.Left; diagram.Style.FretLabelTextSizeRatio = 0.6; diagram.Style.FretLabelTextWidthRatio = 0.5; diagram.Style.FretLabelTextStyle = DiagramTextStyle.Regular; diagram.Style.FretLabelGridPadding = margin / 4.0; diagram.Style.FretLabelTextColor = "Black"; diagram.Style.FretLabelTextOpacity = 1.0; diagram.Style.FretLabelFontFamily = chordOptions.FontFamily; int baseLine = chord.BaseLine; if (baseLine == 0) { diagram.Style.GridNutVisible = true; } else if (chord.BaseLine > 1) { FretLabelPosition flp = new FretLabelPosition(FretLabelSide.Right, 1); diagram.NewFretLabel(flp, baseLine.ToString()); } return(diagram); }