public bool ToDocumentElement(TablatureContext context, ILogger logger, out RhythmSegment rhythmSegment) { rhythmSegment = new RhythmSegment { Range = this.Range }; if (!this.FillRhythmSegmentVoices(context, logger, rhythmSegment)) { return(false); } ChordFingering chordFingering = null; if (this.ChordName != null || this.Fingering != null) { if (this.Fingering != null) { if (!this.Fingering.ToDocumentElement(context, logger, out chordFingering)) { return(false); } } var range = this.ChordName == null // ReSharper disable once PossibleNullReferenceException ? this.Fingering.Range : this.Fingering == null ? this.ChordName.Range : this.ChordName.Range.Union(this.Fingering.Range); rhythmSegment.Chord = new DocumentChord { Name = this.ChordName?.Value, Fingering = chordFingering, Range = range }; } return(true); }
public bool ToDocumentElement(TablatureContext context, ILogger logger, out ChordFingering element) { bool?fingerIndexSpecified = null; var ignoreFingerIndices = false; foreach (var fingering in this.Fingerings) { if (fingering.Fret.Value == Chord.FingeringSkipString || fingering.Fret.Value == 0) { continue; } if (fingerIndexSpecified == null) { fingerIndexSpecified = fingering.FingerIndex != null; continue; } if ((fingering.FingerIndex != null && fingerIndexSpecified == false) || (fingering.FingerIndex == null && fingerIndexSpecified == true)) { logger.Report(LogLevel.Warning, this.Range, Messages.Warning_ChordNotAllFingerIndexSpecified); ignoreFingerIndices = true; break; } } // todo: validate unreasonable fingering element = new ChordFingering { Range = this.Range, Notes = this.Fingerings.Select(f => f.ToDocumentElement(ignoreFingerIndices)).ToArray() }; return(true); }