Module: Musa::Scales
- Included in:
- All
- Defined in:
- lib/musa-dsl/music/scales.rb,
lib/musa-dsl/music/equally-tempered-12-tone-scale-system.rb
Overview
Musical scale system framework.
The Scales module provides a comprehensive framework for working with musical scales, supporting multiple scale systems (equal temperament, just intonation, etc.), scale types (major, minor, chromatic, etc.), and musical operations (transposition, interval calculation, frequency generation, etc.).
Architecture
The framework has a hierarchical structure:
- ScaleSystem: Defines the tuning system (e.g., 12-tone equal temperament)
- ScaleSystemTuning: A scale system with specific A frequency (e.g., A=440Hz)
- ScaleKind: Type of scale (major, minor, chromatic, etc.)
- Scale: A scale kind rooted on a specific pitch (e.g., C major, A minor)
- NoteInScale: A specific note within a scale
Basic Usage
# Access the default system (12-tone equal temperament at A=440Hz)
tuning = Scales::Scales.default_system.default_tuning
# Get a C major scale (root pitch 60 = middle C)
c_major = tuning.major[60]
# Access notes by grade or function
c_major[0] # => Tonic (C)
c_major.tonic # => Tonic (C)
c_major.dominant # => Dominant (G)
c_major[:V] # => Dominant (G)
Advanced Features
- Multiple tuning systems: Support for different A frequencies
- Interval calculations: Named intervals (M3, P5, etc.) and numeric offsets
- Chromatic operations: Sharp, flat, and chromatic movements
- Scale navigation: Move between related scales
- Frequency calculation: Convert pitches to frequencies
- Chord generation: Build chords from scale degrees
Defined Under Namespace
Modules: Scales Classes: ChromaticScaleKind, EquallyTempered12ToneScaleSystem, MajorScaleKind, MinorHarmonicScaleKind, MinorNaturalScaleKind, NoteInScale, Scale, ScaleKind, ScaleSystem, ScaleSystemTuning, TwelveSemitonesScaleSystem