public DiagramBarre NewBarre(BarrePosition position) { DiagramBarre barre = new DiagramBarre(this, position); _barres.Add(barre); return(barre); }
public override sealed void Read(XmlReader xmlReader) { if (null == xmlReader) { throw new ArgumentNullException(nameof(xmlReader)); } using (xmlReader) { if (xmlReader.IsStartElement() && xmlReader.Name == "barre") { Text = xmlReader.GetAttribute("text"); int fret = int.Parse(xmlReader.GetAttribute("fret")); int start = int.Parse(xmlReader.GetAttribute("start")); int end = int.Parse(xmlReader.GetAttribute("end")); Position = new BarrePosition(fret, start, end); while (xmlReader.Read()) { if (xmlReader.IsStartElement() && xmlReader.Name == "style") { Style.Read(xmlReader.ReadSubtree()); } } } } }
public bool ValidPosition(ElementPosition position) { if (null == position) { throw new ArgumentNullException(nameof(position)); } if (position.GetType() == typeof(MarkPosition)) { MarkPosition mp = (MarkPosition)position; return((mp.Fret <= NumFrets + 1) && (mp.String <= NumStrings)); } else if (position.GetType() == typeof(FretLabelPosition)) { FretLabelPosition flp = (FretLabelPosition)position; return(flp.Fret <= NumFrets); } else if (position.GetType() == typeof(BarrePosition)) { BarrePosition bp = (BarrePosition)position; return(bp.Fret <= NumFrets && bp.StartString <= NumStrings && bp.EndString <= NumStrings); } return(false); }
public bool CanRemoveBarreAt(BarrePosition position) { if (null == position) { throw new ArgumentNullException(nameof(position)); } return(HasElementAt(position)); }
public bool CanAddNewBarreAt(BarrePosition position) { if (null == position) { throw new ArgumentNullException(nameof(position)); } if (ValidPosition(position) && !HasElementAt(position)) { foreach (DiagramBarre barre in Barres) { if (barre.Position.Overlaps(position)) { return(false); } } return(true); } return(false); }
public bool Overlaps(BarrePosition position) { if (null == position) { throw new ArgumentNullException(nameof(position)); } if (this == position) { return(true); } if (Fret == position.Fret) { if (StartString == position.StartString || EndString == position.EndString) { return(true); } else if (StartString < position.StartString) { if (EndString >= position.StartString) { return(true); } } else if (StartString > position.StartString) { if (position.EndString >= StartString) { return(true); } } } return(false); }
public DiagramBarre(Diagram parent, BarrePosition position) : base(parent, position) { }
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 override bool Equals(ElementPosition obj) { BarrePosition bp = (obj as BarrePosition); return(null != bp && bp.Fret == Fret && bp.StartString == StartString && bp.EndString == EndString); }
public ElementPosition GetPosition <T>(double x, double y) where T : ElementPosition { GetPositionInternal(x, y, out int @string, out int fret); try { if (typeof(T) == typeof(MarkPosition)) { MarkPosition mp = new MarkPosition(@string, fret); if (ValidPosition(mp)) { return(mp); } } else if (typeof(T) == typeof(FretLabelPosition)) { FretLabelSide?fls = null; if (@string == 0) { fls = FretLabelSide.Left; } else if (@string == NumStrings + 1) { fls = FretLabelSide.Right; } if (fls.HasValue) { FretLabelPosition flp = new FretLabelPosition(fls.Value, fret); if (ValidPosition(flp)) { return(flp); } } } else if (typeof(T) == typeof(BarrePosition)) { // Try to find existing barre covering @string foreach (DiagramBarre barre in Barres) { if (barre.Position.Contains(fret, @string)) { return(barre.Position.Clone()); } } // Find the largest clear range int startString = @string; for (int endString = NumStrings; endString > startString; endString--) { BarrePosition bp = new BarrePosition(fret, startString, endString); if (CanAddNewBarreAt(bp)) { return(bp); } } } } catch (Exception) { } return(null); }
public void RemoveBarre(BarrePosition position) { _barres.Remove((DiagramBarre)ElementAt(position)); }