API Overview
The MusicTheory library provides a comprehensive set of classes and enums for working with music theory concepts programmatically. This reference guide covers all public APIs.
Core Classes
Domain Objects
- Note
Represents a musical note with name, alteration, and octave. Immutable.
- Interval
Represents the distance between two notes. Includes quality and numeric value.
- Scale
Generates notes following specific interval patterns from a root note.
- Chord
Built from a root note and chord type, generates chord tones.
- KeySignature
Represents a musical key with tonic and mode.
- ChordProgression
Analyzes and generates chord progressions in a given key.
Time and Rhythm
- TimeSignature
Represents meter with numerator and denominator.
- Duration
Musical note duration with dots and tuplets.
Enumerations
Note-related Enums
Musical Structure Enums
Time and Duration Enums
Common Methods
Note Methods
Interval Methods
Scale Methods
Chord Methods
KeySignature Methods
ChordProgression Methods
Extension Methods
The library uses extension methods sparingly, preferring explicit methods on domain objects.
Design Principles
Immutability
All domain objects are immutable. Methods that appear to modify objects actually return new instances.
Value Equality
Domain objects implement value equality based on their properties.
Validation
Constructors validate input and throw meaningful exceptions.
Performance Considerations
Caching
Frequently calculated values are cached:
Note frequencies
Interval semitones
Scale note collections
Lazy Evaluation
Scale notes are generated on-demand using yield return
.
Memory Usage
Domain objects are lightweight:
Note: ~12 bytes
Interval: ~8 bytes
Chord: ~16 bytes + notes
Scale: ~16 bytes + pattern
Thread Safety
All domain objects are immutable and therefore thread-safe for read operations. No synchronization is needed when sharing objects between threads.
Versioning
The library follows semantic versioning:
Major version: Breaking changes
Minor version: New features, backward compatible
Patch version: Bug fixes