temporal-music-notation-0.1.4: music notation




Representing pitch



There are four main datatypes Frequency, Pitch, Scale and Tone. Pitch consists of Scale and Tone. Every Pitch can be converted to Frequency (see a absPitch). Scale defines logarithmic mapping from 2d integer coordinates of Tone to 1d double values. Scale is 2d logarithmic grid in frequency domain and Tone is point on that grid.

c1 :: FrequencySource

middle C (261.626 Hz)

a1 :: FrequencySource

middle A (440 Hz)

class Seg a => Pch a whereSource


pitch :: Tone a -> Pitch aSource

data Seg n => Pitch n Source

Pitch consists of Scale and Tone




pitchScale :: Scale
pitchTone :: Tone n


(Eq n, Seg n) => Eq (Pitch n) 
(Show n, Seg n) => Show (Pitch n) 
Seg n => ToneFunctor (Pitch n) 
Seg n => PitchFunctor (Pitch n) 

type Interval = FrequencySource

Musical interval. Ratio between two frequency values.

data Scale Source

Scale defines 2d grid in frequency domain. First value of 2d vector is octave and second is step. Scale consists of base tone, octave interval and individual tone intervals inside octave. Base tone links scale coordinates to frequency coordinates. Base tone is pair (n, f) of integer value and frequency value, Base tone defines that tone n corresponds to frequency f.

For example scales s1 and s2 are equal

import Temporal.Music.Notation.Local.Scales(eqt)

s1 = eqt 0 c1
s2 = eqt 9 a1

This doesn't make much sense for equal temperament. But can be useful for just scales. For example this gives just pythagorean scale in G major

import Temporal.Music.Notation.Local.Scales(pyth)
pythG = pyth 7 (3/2 * c1)

if you write just pyth 0 (3/2 * c1) note (0 :: Tone N12) corresponds to G.




scaleBase :: (Int, Frequency)

start point of the grid, (n, cps) corresponds to (0, n) where n is step id of scaleBase and cps is scaleBase in frequency units.

scaleOctave :: Interval

octave interval

scaleSteps :: Vector Interval

multipliers for each step in octave


scaleSize :: Scale -> IntSource

gives number of steps in one octave.

fromIntervals :: Interval -> [Interval] -> Int -> Frequency -> ScaleSource

fromIntervals makes scale constructor from octave interval and scale step intervals.

type Bend = DoubleSource

represents tone's diversion from scale grid.

data Seg n => Tone n Source

Tone is 2d integer value (octave, step) that can be converted to frequency with some scale. Bend is a level of diversion from scale-tones 1-level bend is equal to 1 step. For tones with fractional bends frequency is calculated with linear interpolation by nearest values in scale.




toneBend :: Bend
toneOctave :: Octave
toneStep :: n


Seg n => Enum (Tone n) 
(Eq n, Seg n) => Eq (Tone n) 
(Eq n, Show n, Seg n) => Num (Tone n) 
(Eq n, Seg n) => Ord (Tone n) 
(Show n, Seg n) => Show (Tone n) 
Seg n => ToneFunctor (Tone n) 

tone :: Seg n => n -> Tone nSource

tone constructs Tone from step value. Bend is set to zero.

toneNum :: Seg n => Tone n -> IntSource

toneNum queries number of steps in scale for given tone. It decodes type value to Int.



class PitchFunctor a whereSource


mapPitch :: (forall n. Seg n => Pitch n -> Pitch n) -> a -> aSource


PitchFunctor a => PitchFunctor (Score a) 
Seg n => PitchFunctor (Pitch n) 
(Seg nVol, Seg nPch) => PitchFunctor (Note nVol nPch a) 


setScale :: PitchFunctor a => Scale -> a -> aSource

setting specific scale

mapBase :: PitchFunctor a => (Frequency -> Frequency) -> a -> aSource

mapping of scale base tone

setBase :: PitchFunctor a => Frequency -> a -> aSource

setting scale base tone

transposeScale :: PitchFunctor a => Step -> a -> aSource

transposeScale shifts scaleSteps by given number. For example if your just scale is defined with middle C as base and you want to transpose it to middle D you can write

res = someScale 2 (wholeTone * c1)
    where wholeTone = 9/8


transposeScale 2 $ someScale 0 c1

And now 0 corresponds to middle C and step multipliers are rearranged so that someScale starts from middle D.


class ToneFunctor a whereSource

transformer for types that contain tone


mapTone :: (forall n. Seg n => Tone n -> Tone n) -> a -> aSource


ToneFunctor a => ToneFunctor (Score a) 
Seg n => ToneFunctor (Tone n) 
Seg n => ToneFunctor (Pitch n) 
(Seg nVol, Seg nPch) => ToneFunctor (Note nVol nPch a) 

setBend :: ToneFunctor a => Bend -> a -> aSource

set bend value

bend :: ToneFunctor a => Bend -> a -> aSource

shift in bends

step :: ToneFunctor a => Step -> a -> aSource

transposition, shift in steps

transp :: ToneFunctor a => Step -> a -> aSource

transposition, shift in steps

low :: ToneFunctor a => a -> aSource

one octave lower

l' :: ToneFunctor a => a -> aSource

shorcut for low

ll' :: ToneFunctor a => a -> aSource

shorcut for lower 2

high :: ToneFunctor a => a -> aSource

one octave higher

h' :: ToneFunctor a => a -> aSource

shorcut for high

hh' :: ToneFunctor a => a -> aSource

shorcut for higher 2

lower :: ToneFunctor a => Int -> a -> aSource

shifts downwards in octaves

higher :: ToneFunctor a => Int -> a -> aSource

shifts upwards in octaves

invert :: ToneFunctor a => Step -> a -> aSource

inverts note around some tone center. Tone center defines two tones octave apart around current note in wich inversion takes place.

For example with center at 5 note c in twelve tone scale [5, 6, 7, 8, 9, bb, 11, c, 1, 2, 3, 4, 5] goes into note bb. Inversion counts number of steps from lower center tone to given tone and then result is higher center tone shifted lower by this number.


frequency :: Seg n => Scale -> Tone n -> FrequencySource

calculates frequency value for given tone on scale grid

absPitch :: Seg n => Pitch n -> FrequencySource

pitch to frequency conversion

toneAsDouble :: Seg s => Tone s -> DoubleSource

flattens tone to double.

scaleAt :: Scale -> Double -> DoubleSource

scale value on doubles

scaleAtInt :: Scale -> Int -> FrequencySource

scale value on integers

scaleStep :: Scale -> Int -> IntervalSource

gives scale multiplier