Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Perform.Pitch

Contents

Description

Representation for scales, pitches, and frequencies (note numbers).

There are many representations for a pitch, at many different levels of abstraction.

Synopsis

# Note

newtype Note Source #

A Note is the most abstract representation of pitch, in that it's simply an unparsed bit of text representing that pitch. Given a Scale, it's expected to name a val call exported by that scale.

Constructors

 Note Text

Instances

 # Methods(==) :: Note -> Note -> Bool #(/=) :: Note -> Note -> Bool # # Methodscompare :: Note -> Note -> Ordering #(<) :: Note -> Note -> Bool #(<=) :: Note -> Note -> Bool #(>) :: Note -> Note -> Bool #(>=) :: Note -> Note -> Bool #max :: Note -> Note -> Note #min :: Note -> Note -> Note # # MethodsshowsPrec :: Int -> Note -> ShowS #showList :: [Note] -> ShowS # # Methods # MethodsformatList :: [Note] -> Doc Source #

# Pitch

data Pitch Source #

A Pitch is a parsed Note. Functions that want to manipulate notes in a scale-independent way can ask the scale to convert to and from a Note. Not all scales use all the fields.

Constructors

 Pitch Fieldspitch_octave :: !Octave pitch_degree :: !Degree

Instances

 # Methods(==) :: Pitch -> Pitch -> Bool #(/=) :: Pitch -> Pitch -> Bool # # Methods(<) :: Pitch -> Pitch -> Bool #(<=) :: Pitch -> Pitch -> Bool #(>) :: Pitch -> Pitch -> Bool #(>=) :: Pitch -> Pitch -> Bool #max :: Pitch -> Pitch -> Pitch #min :: Pitch -> Pitch -> Pitch # # Methods # MethodsshowsPrec :: Int -> Pitch -> ShowS #showList :: [Pitch] -> ShowS # # MethodsformatList :: [Pitch] -> Doc Source # # Methods # This relies on the presence of a pitch val call. Methods # Methods # Methods # Methods

pitch :: Enum pc => Octave -> pc -> Pitch Source #

data Degree Source #

A scale degree, without reference to an octave.

Constructors

 Degree Fieldsdegree_pc :: !PitchClass degree_accidentals :: !AccidentalsIgnored for diatonic scales.

Instances

 # Methods(==) :: Degree -> Degree -> Bool #(/=) :: Degree -> Degree -> Bool # # Methods(<) :: Degree -> Degree -> Bool #(<=) :: Degree -> Degree -> Bool #(>) :: Degree -> Degree -> Bool #(>=) :: Degree -> Degree -> Bool #max :: Degree -> Degree -> Degree #min :: Degree -> Degree -> Degree # # Methods # MethodsshowsPrec :: Int -> Degree -> ShowS #showList :: [Degree] -> ShowS # # MethodsformatList :: [Degree] -> Doc Source # # Methods

type Octave = Int Source #

Just a way to label an octave, either relative or absolute.

type PitchClass = Int Source #

A PitchClass maps directly to a scale degree, which is a letter in traditional Western notation, though this PitchClass may have fewer or greater than 7 notes. The PitchClass is absolute in that it doesn't depend on the tonic of a key.

These numbers are expected to wrap around at the octave, so they usually use modular arithmetic, but if an octave is not handy (i.e. they're not in a Pitch), then steps exceeding an octave will be wrapped into an octave when one is available.

Positive for sharps, negative for flats.

type Semi = Int Source #

Number of semitones. This is an absolute measure from octave 0, regardless of whether the scale has notes at octave 0. This is so you can convert between Semis and the similarly absolute Pitch in the same way for all scales.

type FSemi = Double Source #

This is like Semi, but floating point.

type Step = Int Source #

This is a relative amount of transposition. It could be either chromatic or diatonic.

Add diatonic steps. This doesn't deal with key signatures or non-diatonic scales.

The middle octave. The "center" of a scale should be oriented around this.

# Input

data Input Source #

A physically played note on some input device. This hasn't been mapped to a scale yet, so the Pitch is in the context of the device's layout.

I have 3 kinds of kbds:

ASCII has 10 white keys, and black keys between each one. It should be relative, so that C or sa is always on Q and Z, and if the octave is <10 then it will wrap on the same row.

MIDI has the usual piano layout. It's absolute, so that a relative scale can start at keys other than C, if that would be convenient for the layout. The octave is rounded up to the nearest multiple of 7, and the extra keys are unused, so the octave always starts at C.

Continuum has no keys, just NNs. So it gets the scale degree that's closest to the given NN. That's different from the MIDI kbd because the MIDI kbd never wants a key to emit something between notes. TODO not supported yet

Constructors

 Input !KbdType !Pitch !Frac

Instances

 # Methods(==) :: Input -> Input -> Bool #(/=) :: Input -> Input -> Bool # # MethodsshowsPrec :: Int -> Input -> ShowS #showList :: [Input] -> ShowS # # MethodsformatList :: [Input] -> Doc Source #

data KbdType Source #

Constructors

 PianoKbd An absolute kbd maps the same key to the same absolute pitch, regardless of the key. This is the case for a piano style kbd. This is consistent with convention, but also the piano kbd has a fixed layout of white and black keys. So if you e.g. transpose A-major to start on C, then you have a mysterious black key in between B and C, and no way to play C#. AsciiKbd A relative kbd always maps the same key to the same relative pitch. This is appropriate for the ASCII kbd, because it has "black keys" between every white key, so scales can be transposed freely.

Instances

 # Methods(==) :: KbdType -> KbdType -> Bool #(/=) :: KbdType -> KbdType -> Bool # # MethodsshowList :: [KbdType] -> ShowS #

type Frac = Double Source #

A number between -1 and 1 exclusive, representing the portion of the way between two scale degrees. I could have used "Cents" for this, but that implies equal temperedness.

# NoteNumber

newtype NoteNumber Source #

This is equal tempered scale notes with the same definition as MIDI, so MIDI note 0 is NoteNumber 0, at 8.176 Hz, and is -1c. Middle C (4c) is NoteNumber 60.

PSignals are converted into this before performance since performance doesn't understand scales.

Constructors

 NoteNumber Double

Instances

 # Methods # Methods # Methods # Methods # Methods # Methods # MethodsproperFraction :: Integral b => NoteNumber -> (b, NoteNumber) #truncate :: Integral b => NoteNumber -> b #round :: Integral b => NoteNumber -> b #ceiling :: Integral b => NoteNumber -> b #floor :: Integral b => NoteNumber -> b # # MethodsshowList :: [NoteNumber] -> ShowS # # MethodsformatList :: [NoteNumber] -> Doc Source # # Methods # Methods # Methods # Methods # Methods # Methods # Methods

nn :: Real a => a -> NoteNumber Source #

True if the NoteNumbers are close enough that they sound the same.

# Hz

type Hz = Double Source #

This is absolute non-logarithmic frequency.

Negative hz will result in NaN. TODO take an abs or throw an error, or let the NaN propagate?

# Scale

newtype ScaleId Source #

Constructors

 ScaleId Text

Instances

 # Methods(==) :: ScaleId -> ScaleId -> Bool #(/=) :: ScaleId -> ScaleId -> Bool # # Methods(<) :: ScaleId -> ScaleId -> Bool #(<=) :: ScaleId -> ScaleId -> Bool #(>) :: ScaleId -> ScaleId -> Bool #(>=) :: ScaleId -> ScaleId -> Bool # # Methods # MethodsshowList :: [ScaleId] -> ShowS # # Methods # MethodsformatList :: [ScaleId] -> Doc Source # # Methods

Usually this means to use the scale currently in scope.

data Transpose Source #

A generic transposition, for operations that can transpose diatonically, chromatically, or by absolute NoteNumber.

Constructors

 Chromatic Double Diatonic Double Nn Double Nn is scale-independent, so it's not suitable for symbolic transposition, but it's still useful for pitch transposition.

Instances

 # Methods # Methods # MethodsshowList :: [Transpose] -> ShowS # # MethodsformatList :: [Transpose] -> Doc Source # # Methods # Methods # Methods # Methods # VNums can also be coerced into chromatic transposition, so you can write a plain number if you don't care about diatonic.This is different from Duration, which does not default an untyped literal, so you have to supply the type explicitly. The rationale is that many scales don't have diatonic or chromatic, and it would be annoying to have to specify one or the other when it was definitely irrelevant. But the RealTime ScoreTime distinction is universal, there is no single default that is appropriate for all calls. So they have to specify a default by taking a DefaultScore or DefaultReal, or require the caller to distinguish with Duration. Methods

newtype Key Source #

Diatonic transposition often requires a Key for context.

This is not very strongly typed, because it's intended to be scale independent, and not every scale will have the same values for key and mode.

Constructors

 Key Text

Instances

 # Methods(==) :: Key -> Key -> Bool #(/=) :: Key -> Key -> Bool # # Methodscompare :: Key -> Key -> Ordering #(<) :: Key -> Key -> Bool #(<=) :: Key -> Key -> Bool #(>) :: Key -> Key -> Bool #(>=) :: Key -> Key -> Bool #max :: Key -> Key -> Key #min :: Key -> Key -> Key # # Methods # MethodsshowsPrec :: Int -> Key -> ShowS #showList :: [Key] -> ShowS # # MethodsformatList :: [Key] -> Doc Source # # Methods # Methods