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

Safe HaskellNone

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

Eq Note # 

Methods

(==) :: Note -> Note -> Bool #

(/=) :: Note -> Note -> Bool #

Ord Note # 

Methods

compare :: Note -> Note -> Ordering #

(<) :: Note -> Note -> Bool #

(<=) :: Note -> Note -> Bool #

(>) :: Note -> Note -> Bool #

(>=) :: Note -> Note -> Bool #

max :: Note -> Note -> Note #

min :: Note -> Note -> Note #

Show Note # 
String.IsString Note # 
Pretty.Pretty Note # 

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 

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

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.

type Accidentals = Int Source #

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_pc :: PitchClass -> PitchClass -> Pitch -> Pitch Source #

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

middle_octave :: Octave Source #

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 

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.

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

Eq NoteNumber # 
Fractional NoteNumber # 
Num NoteNumber # 
Ord NoteNumber # 
Read.Read NoteNumber # 
Real NoteNumber # 
RealFrac NoteNumber # 
Show NoteNumber # 
Pretty.Pretty NoteNumber # 
ApproxEq.ApproxEq NoteNumber # 
Serialize.Serialize NoteNumber # 
ShowVal.ShowVal NoteNumber # 
ToVal NoteNumber # 
TypecheckNum NoteNumber # 
ToVal NoteNumber # 
Typecheck NoteNumber # 

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

nns_equal :: NoteNumber -> NoteNumber -> Bool Source #

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

Hz

type Hz = Double Source #

This is absolute non-logarithmic frequency.

hz_to_nn :: Hz -> NoteNumber Source #

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

Scale

empty_scale :: ScaleId Source #

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

Eq Transpose # 
Ord Transpose # 
Show Transpose # 
Pretty.Pretty Transpose # 
ShowVal.ShowVal Transpose # 
ToVal Transpose # 

Methods

to_val :: Transpose -> Val Source #

TypecheckNum Transpose # 
ToVal Transpose # 

Methods

to_val :: Transpose -> Val Source #

Typecheck Transpose #

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.

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