Copyright | (c) Hans Hoglund 2012-2014 |
---|---|

License | BSD-style |

Maintainer | hans@hanshoglund.se |

Stability | experimental |

Portability | non-portable (TF,GNTD) |

Safe Haskell | None |

Language | Haskell2010 |

Provides functions for manipulating pitch.

- type family Pitch s :: *
- type family SetPitch b s :: *
- type Interval a = Diff (Pitch a)
- class HasPitches s t => HasPitch s t where
- class (Transformable (Pitch s), Transformable (Pitch t), SetPitch (Pitch t) s ~ t) => HasPitches s t where
- type HasPitch' a = HasPitch a a
- type HasPitches' a = HasPitches a a
- pitch' :: HasPitch' s => Lens' s (Pitch s)
- pitches' :: HasPitches' s => Traversal' s (Pitch s)
- type PitchPair v w = (Num (Scalar v), IsInterval v, IsPitch w)
- type AffinePair v w = (VectorSpace v, AffineSpace w)
- type Transposable a = (HasPitches' a, AffinePair (Interval a) (Pitch a), PitchPair (Interval a) (Pitch a))
- up :: Transposable a => Interval a -> a -> a
- down :: Transposable a => Interval a -> a -> a
- above :: (Semigroup a, Transposable a) => Interval a -> a -> a
- below :: (Semigroup a, Transposable a) => Interval a -> a -> a
- octavesUp :: Transposable a => Scalar (Interval a) -> a -> a
- octavesDown :: Transposable a => Scalar (Interval a) -> a -> a
- _15va :: Transposable a => a -> a
- _8va :: Transposable a => a -> a
- _8vb :: Transposable a => a -> a
- _15vb :: Transposable a => a -> a
- invertPitches :: Transposable a => Pitch a -> a -> a
- highest :: (HasPitches' a, Ord (Pitch a)) => a -> Maybe (Pitch a)
- lowest :: (HasPitches' a, Ord (Pitch a)) => a -> Maybe (Pitch a)
- meanPitch :: (HasPitches' a, Fractional (Pitch a)) => a -> Maybe (Pitch a)

# Pitch type

type family Pitch s :: * Source

This type fuction is used to access the pitch type for a given type.

type Pitch Bool = Bool | |

type Pitch Char = Char | |

type Pitch Double = Double | |

type Pitch Float = Float | |

type Pitch Int = Int | |

type Pitch Integer = Integer | |

type Pitch Ordering = Ordering | |

type Pitch () = () | |

type Pitch [a] = Pitch a | |

type Pitch (Maybe a) = Pitch a | |

type Pitch (Sum a) = Pitch a | |

type Pitch (Seq a) = Pitch a | |

type Pitch (Note a) = Pitch a | |

type Pitch (Voice a) = Pitch a | |

type Pitch (Placed a) = Pitch a | |

type Pitch (Track a) = Pitch a | |

type Pitch (Event a) = Pitch a | |

type Pitch (Score a) = Pitch a | |

type Pitch (Aligned a) = Pitch a | |

type Pitch (Behavior a) = Behavior a | |

type Pitch (TieT a) = Pitch a | |

type Pitch (SlideT a) = Pitch a | |

type Pitch (TextT a) = Pitch a | |

type Pitch (HarmonicT a) = Pitch a | |

type Pitch (TremoloT a) = Pitch a | |

type Pitch (ColorT a) = Pitch a | |

type Pitch (Either c a) = Pitch a | |

type Pitch (c, a) = Pitch a | |

type Pitch (Map k a) = Pitch a | |

type Pitch (Couple c a) = Pitch a | |

type Pitch (PartT p a) = Pitch a | |

type Pitch (DynamicT p a) = Pitch a | |

type Pitch (ArticulationT p a) = Pitch a |

type family SetPitch b s :: * Source

This type fuction is used to update the pitch type for a given type. The first argument is the new type.

# HasPitch classes

class HasPitches s t => HasPitch s t where Source

Class of types that provide a single pitch.

pitch :: Lens s t (Pitch s) (Pitch t) Source

Access the pitch.

As this is a `Traversal`

, you can use all combinators from the lens package,
for example:

`pitch`

.~ c :: (`HasPitch'`

a,`IsPitch`

a) => a -> a`pitch`

+~ 2 :: (`HasPitch'`

a,`Num`

(`Pitch`

a)) => a -> a`pitch`

%~`succ`

:: (`HasPitch'`

a,`Enum`

(`Pitch`

a)) => a -> a`view`

`pitch`

::`HasPitches'`

a => a ->`Pitch`

a`set`

`pitch`

::`HasPitches`

a b =>`Pitch`

b -> a -> b`over`

`pitch`

::`HasPitches`

a b => (`Pitch`

a ->`Pitch`

b) -> a -> b

class (Transformable (Pitch s), Transformable (Pitch t), SetPitch (Pitch t) s ~ t) => HasPitches s t where Source

Class of types that provide zero or more pitches.

pitches :: Traversal s t (Pitch s) (Pitch t) Source

Access all pitches.

As this is a `Traversal`

, you can use all combinators from the lens package,
for example:

`toListOf`

`pitches`

::`HasPitches'`

a => a -> [`Pitch`

a]`allOf`

`pitches`

:: (`HasPitches'`

a) => (`Pitch`

a ->`Bool`

) -> a ->`Bool`

`maximumOf`

`pitches`

:: (`HasPitches'`

a,`Ord`

(`Pitch`

a)) => a ->`Maybe`

(`Pitch`

a)`set`

`pitches`

::`HasPitches`

a b =>`Pitch`

b -> a -> b`over`

`pitches`

::`HasPitches`

a b => (`Pitch`

a ->`Pitch`

b) -> a -> b

## Simple versions

type HasPitches' a = HasPitches a a Source

pitch' :: HasPitch' s => Lens' s (Pitch s) Source

Access the pitch.

Same as `pitch`

, but without polymorphic update.

pitches' :: HasPitches' s => Traversal' s (Pitch s) Source

Access all pitches.

Same as `pitches`

, but without polymorphic update.

# Transposition

type AffinePair v w = (VectorSpace v, AffineSpace w) Source

type Transposable a = (HasPitches' a, AffinePair (Interval a) (Pitch a), PitchPair (Interval a) (Pitch a)) Source

Class of types that can be transposed, inverted and so on.

up :: Transposable a => Interval a -> a -> a Source

Transpose (translate) up.

`>>>`

eb`up m3 (c :: Pitch)`

`>>>`

[g,a,b]`up _P5 [c,d,e :: Pitch]`

`>>>`

[g,a,b]`up _P5 [440 :: Hertz, 442, 810]`

down :: Transposable a => Interval a -> a -> a Source

Transpose (translate) down.

`>>>`

a`down m3 (c :: Pitch)`

`>>>`

[f_,g_,a_]`down _P5 [c,d,e]`

above :: (Semigroup a, Transposable a) => Interval a -> a -> a Source

Add the given interval above.

`>>>`

[c,c']`above _P8 [c :: Pitch]`

below :: (Semigroup a, Transposable a) => Interval a -> a -> a Source

Add the given interval below.

`>>>`

[c,c_]`below _P8 [c :: Pitch]`

octavesUp :: Transposable a => Scalar (Interval a) -> a -> a Source

Transpose up by the given number of octaves.

`>>>`

c''`octavesUp 2 (c :: Pitch)`

`>>>`

[c',d',e']`octavesUp 1 [c,d,e]`

`>>>`

[c_,d_,e_]`octavesUp (-1) [c,d,e]`

octavesDown :: Transposable a => Scalar (Interval a) -> a -> a Source

Transpose down by the given number of octaves.

`>>>`

c__`octavesDown 2 (c :: Pitch)`

`>>>`

[c_,d_,e_]`octavesDown 1 [c,d,e]`

`>>>`

[c',d',e']`octavesDown (-1) [c,d,e]`

_15va :: Transposable a => a -> a Source

Same as

.`octavesUp`

2

_8va :: Transposable a => a -> a Source

Same as

.`octavesUp`

1

_8vb :: Transposable a => a -> a Source

Same as

.`octavesDown`

1

_15vb :: Transposable a => a -> a Source

Same as

.`octavesDown`

2

# Inversion

invertPitches :: Transposable a => Pitch a -> a -> a Source

Invert pitches.

# Folds

highest :: (HasPitches' a, Ord (Pitch a)) => a -> Maybe (Pitch a) Source

Extract the highest pitch. Returns `Nothing`

if there are none.

lowest :: (HasPitches' a, Ord (Pitch a)) => a -> Maybe (Pitch a) Source

Extract the lowest pitch. Returns `Nothing`

if there are none.

meanPitch :: (HasPitches' a, Fractional (Pitch a)) => a -> Maybe (Pitch a) Source

Extract the average pitch. Returns `Nothing`

if there are none.