| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Harmonic.Rules.Types.Pitch
Description
This module defines PitchClass as a proper cyclic group with modular
arithmetic. All pitch operations automatically wrap within the octave.
Academic Lineage
Data Science In The Creative Process (South, 2018): the MusicData module's pitch-class algebra, where pitch classes are treated as elements of ℤ₁₂ with modular arithmetic operations.
Design
This module sits in the Rules (R) layer: the ℤ₁₂ algebra is part of the language the system's validity rules are written in. (R, E and T describe the creative system as a whole, not individual types — transposition and interval measurement here are algebra, and become traversal or evaluation only in the layers that use them for those purposes.)
Pitch classes are elements of ℤ₁₂, the integers modulo 12:
- Addition: transposition
- Subtraction: interval measurement
- Identity: unison (0)
- Inverse: octave complement
Synopsis
- newtype PitchClass = P {
- unPitchClass :: Int
- mkPitchClass :: Int -> PitchClass
- data NoteName
- pitchClass :: NoteName -> PitchClass
- notesToPCs :: [NoteName] -> [Int]
- sharp :: PitchClass -> NoteName
- flat :: PitchClass -> NoteName
- enharmFromNoteName :: NoteName -> PitchClass -> NoteName
- transpose :: Int -> PitchClass -> PitchClass
- interval :: PitchClass -> PitchClass -> PitchClass
- invert :: PitchClass -> PitchClass
- allPitchClasses :: [PitchClass]
- pcSet :: [Int] -> [PitchClass]
- zeroForm :: [Int] -> [PitchClass]
Core Types
newtype PitchClass Source #
PitchClass represents an element of ℤ₁₂, the cyclic group of integers mod 12.
The Num instance ensures all arithmetic automatically wraps to [0..11].
Constructors
| P | |
Fields
| |
Instances
mkPitchClass :: Int -> PitchClass Source #
Smart constructor ensuring values stay in [0..11]
Enharmonic Note Names
All standard enharmonic note names within an octave
Instances
| Bounded NoteName Source # | |
| Enum NoteName Source # | |
Defined in Harmonic.Rules.Types.Pitch | |
| Read NoteName Source # | |
| Show NoteName Source # | Custom Show instance: renders sharp notation C' as C#, D' as D#, etc. (matches legacy behavior and musical convention) |
| Eq NoteName Source # | |
| Ord NoteName Source # | |
Defined in Harmonic.Rules.Types.Pitch | |
pitchClass :: NoteName -> PitchClass Source #
Extract pitch class from a note name
notesToPCs :: [NoteName] -> [Int] Source #
Convert a list of NoteNames to pitch-class integers Useful for defining chord progressions with note names
sharp :: PitchClass -> NoteName Source #
Map pitch class to sharp enharmonic spelling
flat :: PitchClass -> NoteName Source #
Map pitch class to flat enharmonic spelling
enharmFromNoteName :: NoteName -> PitchClass -> NoteName Source #
Helper function for mapping NoteName to enharmonic function. This determines whether to use sharp or flat spelling based on the root note of a chord (for consistent enharmonic spelling). Ported from legacy MusicData.hs
Transposition (Group Action)
transpose :: Int -> PitchClass -> PitchClass Source #
Transpose a pitch class by an interval (group addition)
interval :: PitchClass -> PitchClass -> PitchClass Source #
Calculate the interval between two pitch classes (group subtraction) Returns the ascending interval from first to second.
invert :: PitchClass -> PitchClass Source #
Invert a pitch class (octave complement) The inverse of n is (12 - n) mod 12
Utilities
allPitchClasses :: [PitchClass] Source #
All 12 pitch classes
pcSet :: [Int] -> [PitchClass] Source #
Convert a list of integers to a set of unique pitch classes
zeroForm :: [Int] -> [PitchClass] Source #
Normalize a pitch set to start from zero (transposition-invariant form) Ported from legacy MusicData.hs