< Summary

Information
Class: MusicTheory.Theory.Interval.IntervalName
Assembly: MusicTheory
File(s): /home/runner/work/MusicTheory/MusicTheory/Theory/Interval/interval.cs
Line coverage
61%
Covered lines: 8
Uncovered lines: 5
Coverable lines: 13
Total lines: 83
Line coverage: 61.5%
Branch coverage
37%
Covered branches: 3
Total branches: 8
Branch coverage: 37.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Quality()100%11100%
ToJapaneseString()37.5%14854.54%
ToString()100%11100%

File(s)

/home/runner/work/MusicTheory/MusicTheory/Theory/Interval/interval.cs

#LineLine coverage
 1using MusicTheory.Theory.Pitch;
 2
 3namespace MusicTheory.Theory.Interval
 4{
 5    public enum IntervalQuality { Perfect, Major, Minor, Augmented, Diminished, DoublyAugmented, DoublyDiminished }
 6
 407    public readonly record struct IntervalName(IntervalQuality Quality, int Number)
 8    {
 79        public string ToJapaneseString() => Quality switch
 710        {
 311            IntervalQuality.Perfect => $"完全{Number}",
 012            IntervalQuality.Major => $"長{Number}",
 213            IntervalQuality.Minor => $"短{Number}",
 214            IntervalQuality.Augmented => $"増{Number}",
 015            IntervalQuality.Diminished => $"減{Number}",
 016            IntervalQuality.DoublyAugmented => $"重増{Number}",
 017            IntervalQuality.DoublyDiminished => $"重減{Number}",
 018            _ => $"?{Number}"
 719        };
 20
 121        public override string ToString() => $"{Quality} {Number}";
 22    }
 23
 24    public static class IntervalUtils
 25    {
 26    public static IntervalName GetIntervalName(FunctionalInterval ivl)
 27        {
 28            int semitones = ivl.Semitones;
 29            int octaves = semitones / 12;
 30            int remainder = semitones % 12;
 31            int number = octaves * 7 + (remainder switch
 32            {
 33                0 => 1,
 34                1 => 2,
 35                2 => 2,
 36                3 => 2,
 37                4 => 3,
 38                5 => 3,
 39                6 => 4,
 40                7 => 4,
 41                8 => 4,
 42                9 => 5,
 43                10 => 6,
 44                11 => 6,
 45                _ => 1
 46            });
 47
 48            IntervalQuality quality = semitones switch
 49            {
 50                0 => IntervalQuality.Perfect,
 51                1 => IntervalQuality.DoublyDiminished,
 52                2 => IntervalQuality.Minor,
 53                3 => IntervalQuality.Major,
 54                4 => IntervalQuality.Minor,
 55                5 => IntervalQuality.Major,
 56                6 => IntervalQuality.Perfect,
 57                7 => IntervalQuality.Augmented,
 58                8 => IntervalQuality.DoublyAugmented,
 59                9 => IntervalQuality.Perfect,
 60                10 => IntervalQuality.Minor,
 61                11 => IntervalQuality.Major,
 62                12 => IntervalQuality.Minor,
 63                13 => IntervalQuality.Major,
 64                14 => IntervalQuality.Perfect,
 65                _ => IntervalQuality.Augmented
 66            };
 67
 68            return new IntervalName(quality, number);
 69        }
 70
 71    public static FunctionalInterval Between(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b) => new 
 72
 73    public static int DegreeBetween(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b)
 74        {
 75            int aIndex = (int)a.Spelling.Letter + a.Octave * 7;
 76            int bIndex = (int)b.Spelling.Letter + b.Octave * 7;
 77            return bIndex - aIndex + 1;
 78        }
 79
 80        public static bool IsEnharmonic(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b)
 81            => PitchUtils.ToPc(a).Pc == PitchUtils.ToPc(b).Pc;
 82    }
 83}