| | 1 | | using System.Collections.Generic; |
| | 2 | |
|
| | 3 | | namespace MusicTheory.Theory.Harmony; |
| | 4 | |
|
| | 5 | | public readonly record struct VoiceLeadingFlags(bool Range, bool Spacing, bool Overlap, bool ParallelPerfects); |
| | 6 | |
|
| | 7 | | public readonly record struct ProgressionDiagnosticsResult( |
| 4 | 8 | | List<(int index, VoiceLeadingFlags flags)> PerIndex, |
| 1 | 9 | | int TotalRange, |
| 1 | 10 | | int TotalSpacing, |
| 1 | 11 | | int TotalOverlap, |
| 1 | 12 | | int TotalParallelPerfects |
| | 13 | | ); |
| | 14 | |
|
| | 15 | | public static class ProgressionDiagnostics |
| | 16 | | { |
| | 17 | | public static ProgressionDiagnosticsResult AnalyzeVoicings(IReadOnlyList<FourPartVoicing?> voicings) |
| | 18 | | { |
| | 19 | | var list = new List<(int, VoiceLeadingFlags)>(voicings.Count); |
| | 20 | | int sumR = 0, sumS = 0, sumO = 0, sumP = 0; |
| | 21 | | for (int i = 0; i < voicings.Count; i++) |
| | 22 | | { |
| | 23 | | bool r = false, s = false, o = false, p = false; |
| | 24 | | if (voicings[i] is FourPartVoicing v) |
| | 25 | | { |
| | 26 | | r = VoiceLeadingRules.HasRangeViolation(v); |
| | 27 | | s = VoiceLeadingRules.HasSpacingViolations(v); |
| | 28 | | if (i > 0 && voicings[i - 1] is FourPartVoicing prev) |
| | 29 | | { |
| | 30 | | o = VoiceLeadingRules.HasOverlap(prev, v); |
| | 31 | | p = VoiceLeadingRules.HasParallelPerfects(prev, v); |
| | 32 | | } |
| | 33 | | } |
| | 34 | | if (r) sumR++; |
| | 35 | | if (s) sumS++; |
| | 36 | | if (o) sumO++; |
| | 37 | | if (p) sumP++; |
| | 38 | | list.Add((i, new VoiceLeadingFlags(r, s, o, p))); |
| | 39 | | } |
| | 40 | | return new ProgressionDiagnosticsResult(list, sumR, sumS, sumO, sumP); |
| | 41 | | } |
| | 42 | | } |