| | 1 | | namespace MusicTheory.Theory.Harmony; |
| | 2 | |
|
| | 3 | | public enum TonalFunction { Tonic, Subdominant, Dominant, Unknown } |
| | 4 | |
|
| | 5 | | public enum RomanNumeral |
| | 6 | | { |
| | 7 | | I, II, III, IV, V, VI, VII, |
| | 8 | | i, ii, iii, iv, v, vi, vii |
| | 9 | | } |
| | 10 | |
|
| 72388 | 11 | | public readonly record struct Key(int TonicMidi, bool IsMajor) |
| | 12 | | { |
| 12530 | 13 | | public int ScaleDegreeMidi(int degree) => TonicMidi + (IsMajor ? MajorSteps[degree % 7] : MinorSteps[degree % 7]); |
| 1 | 14 | | private static readonly int[] MajorSteps = { 0, 2, 4, 5, 7, 9, 11 }; |
| 1 | 15 | | private static readonly int[] MinorSteps = { 0, 2, 3, 5, 7, 8, 10 }; |
| | 16 | | } |
| | 17 | |
|
| | 18 | | public static class RomanNumeralUtils |
| | 19 | | { |
| | 20 | | public static TonalFunction FunctionOf(RomanNumeral rn) => rn switch |
| | 21 | | { |
| | 22 | | RomanNumeral.I or RomanNumeral.i => TonalFunction.Tonic, |
| | 23 | | RomanNumeral.III or RomanNumeral.iii or RomanNumeral.VI or RomanNumeral.vi => TonalFunction.Tonic, |
| | 24 | | RomanNumeral.IV or RomanNumeral.iv or RomanNumeral.II or RomanNumeral.ii => TonalFunction.Subdominant, |
| | 25 | | RomanNumeral.V or RomanNumeral.v or RomanNumeral.VII or RomanNumeral.vii => TonalFunction.Dominant, |
| | 26 | | _ => TonalFunction.Unknown |
| | 27 | | }; |
| | 28 | | } |