public Utf8String Substring(Range range) { (int start, int length) = range.GetOffsetAndLength(Length); return(Substring(start, length)); }
public static (Note[] notes, bool sharp) Notes(Note root, ModeEnum mode) { var funcRelative = FunctionalScale.GetAbsouluteOffsetFromRoot(mode, 1); var sharp = root.Name.Contains(Helpers.SHARPCHAR); if (root.Name == "C") { sharp = true; } if (root.Name == "G") { sharp = true; } if (root.Name == "D") { sharp = true; } if (root.Name == "A") { sharp = true; } if (root.Name == "E") { sharp = true; } if (root.Name.Contains(Helpers.FLATCHAR)) { sharp = false; } var names = sharp ? Helpers.Sharps : Helpers.Flats; var idxOfRootInNames = Array.IndexOf(names, root.Name); var result = new Note[funcRelative.Length]; var range = new System.Range(0, result.Length - 1); //Remove Last element as it is the root repeated... FIXME? for (int i = 0; i < funcRelative.Length; i++) { var idxCurrentName = (funcRelative[i] + idxOfRootInNames) % names.Length; result[i] = new Note(names[idxCurrentName]); } //FIXME Dirty WET hack... bool tryagain = false; var seenChar = new List <char>(); for (int i = 0; i < result.Length - 1; i++) { var firstLetterInRoot = result[i].Name.ToCharArray()[0]; if (seenChar.Contains(firstLetterInRoot)) { tryagain = true; } else { seenChar.Add(firstLetterInRoot); } } if (tryagain) { sharp = !sharp; names = sharp ? Helpers.Sharps : Helpers.Flats; result = new Note[funcRelative.Length]; range = new System.Range(0, result.Length - 1); //Remove Last element as it is the root repeated... FIXME? for (int i = 0; i < funcRelative.Length; i++) { var idxCurrentName = (funcRelative[i] + idxOfRootInNames) % names.Length; result[i] = new Note(names[idxCurrentName]); } } var resultWithSharpFlag = (notes : result[range], sharp : sharp); return(resultWithSharpFlag); }
public static Terminal Range(System.Range range) => Range((char)range.Start.Value, (char)range.End.Value);