Interval API Reference
Complete API documentation for the Interval
class.
Class Definition
Constructors
Interval(IntervalQuality, int)
Creates a new interval with the specified quality and numeric value.
Parameters:
quality
: The interval quality (Diminished, Minor, Major, Perfect, Augmented)number
: The interval number (1-15 typically)
Exceptions:
ArgumentException
: If the quality is invalid for the given interval numberArgumentOutOfRangeException
: If number is less than 1
Validation Rules:
Perfect quality is only valid for unison (1), 4th, 5th, and octave (8)
Major/Minor quality is only valid for 2nd, 3rd, 6th, and 7th
Diminished/Augmented can be used with any interval
Examples:
Properties
Quality
Gets the quality of the interval.
Number
Gets the numeric value of the interval (1 = unison, 2 = second, etc.).
Semitones
Gets the number of semitones (half steps) in the interval.
Calculation: The semitone count is calculated based on:
The diatonic interval (based on the number)
The chromatic adjustment (based on the quality)
Examples:
Major 3rd = 4 semitones
Perfect 5th = 7 semitones
Minor 7th = 10 semitones
Instance Methods
IsEnharmonicWith(Interval)
Determines if this interval is enharmonically equivalent to another.
Parameters:
other
: The interval to compare with
Returns: True if both intervals span the same number of semitones
Example:
Invert()
Inverts the interval.
Returns: The inverted interval
Inversion Rules:
Number: 9 - original number (for simple intervals)
Quality:
Major ↔ Minor
Augmented ↔ Diminished
Perfect remains Perfect
Examples:
ToString()
Returns a string representation of the interval.
Format: "{Quality} {Number}{Suffix}"
Examples:
Perfect Unison → "Perfect Unison"
Major 3rd → "Major 3rd"
Perfect 5th → "Perfect 5th"
Minor 7th → "Minor 7th"
Augmented 4th → "Augmented 4th"
Equals(Interval?)
Determines if this interval equals another interval.
Note: Compares by quality and number, not by semitones.
GetHashCode()
Returns the hash code for the interval.
Static Methods
Between(Note, Note)
Calculates the interval between two notes.
Parameters:
lower
: The lower notehigher
: The higher note
Returns: The interval from lower to higher
Algorithm:
Calculate the numeric interval based on note names
Calculate the exact semitone distance
Determine the appropriate quality
Example:
FromSemitones(int)
Creates an interval from a semitone count.
Parameters:
semitones
: Number of semitones
Returns: An interval (prefers standard spellings)
Note: This method returns the most common spelling for the given semitone count.
Example:
Operators
Equality Operators
Compare intervals by quality and number.
Example:
Interval Reference Tables
Simple Intervals (Within an Octave)
Number | Perfect | Diminished | Minor | Major | Augmented |
---|---|---|---|---|---|
1 | 0 | -1 | - | - | 1 |
2 | - | 0 | 1 | 2 | 3 |
3 | - | 2 | 3 | 4 | 5 |
4 | 5 | 4 | - | - | 6 |
5 | 7 | 6 | - | - | 8 |
6 | - | 7 | 8 | 9 | 10 |
7 | - | 9 | 10 | 11 | 12 |
8 | 12 | 11 | - | - | 13 |
Compound Intervals (Beyond an Octave)
Number | Common Name | Semitones | Simple Equivalent |
---|---|---|---|
9 | Ninth | 14 (Major) | 2nd |
10 | Tenth | 16 (Major) | 3rd |
11 | Eleventh | 17 (Perfect) | 4th |
12 | Twelfth | 19 (Perfect) | 5th |
13 | Thirteenth | 21 (Major) | 6th |
14 | Fourteenth | 23 (Major) | 7th |
15 | Fifteenth | 24 (Perfect) | Octave |
Common Patterns
Creating Common Intervals
Working with Interval Collections
Interval Analysis
Error Handling
Invalid Quality for Number
Interval Calculation Edge Cases
Performance Notes
Semitone calculation is performed once in constructor
Interval comparison uses cached semitone values
String representation is generated on demand
Static factory methods use lookup tables for efficiency
Thread Safety
The Interval
class is immutable and thread-safe. Multiple threads can safely:
Read all properties
Call all methods
Share Interval instances
No synchronization is needed.