Karya, built on 2018-05-31T02:46:59 (patch 0a1a35479c514820d77330ae8a978975ba22a47a)

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 # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Note # 
Instance details

Defined in Perform.Pitch

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 # 
Instance details

Defined in Perform.Pitch

String.IsString Note # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty Note # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Note # 
Instance details

Defined in Perform.Pitch

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 
Instances
Eq Pitch # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Pitch # 
Instance details

Defined in Perform.Pitch

Methods

compare :: Pitch -> Pitch -> Ordering #

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

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

(>) :: Pitch -> Pitch -> Bool #

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

max :: Pitch -> Pitch -> Pitch #

min :: Pitch -> Pitch -> Pitch #

Read.Read Pitch # 
Instance details

Defined in Perform.Pitch

Show Pitch # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty Pitch # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Pitch # 
Instance details

Defined in Perform.Pitch

ShowVal.ShowVal Pitch #

This relies on the presence of a pitch val call.

Instance details

Defined in Perform.Pitch

Methods

show_val :: Pitch -> Text Source #

Notation Pitch # 
Instance details

Defined in Solkattu.Instrument.Sargam

ToVal Pitch # 
Instance details

Defined in Derive.RestrictedEnviron

Methods

to_val :: Pitch -> Val Source #

ToVal Pitch # 
Instance details

Defined in Derive.Typecheck

Methods

to_val :: Pitch -> Val Source #

Typecheck Pitch # 
Instance details

Defined in Derive.Typecheck

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

data Degree Source #

A scale degree, without reference to an octave.

Constructors

Degree 

Fields

Instances
Eq Degree # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Degree # 
Instance details

Defined in Perform.Pitch

Read.Read Degree # 
Instance details

Defined in Perform.Pitch

Show Degree # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty Degree # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Degree # 
Instance details

Defined in Perform.Pitch

Notation Degree # 
Instance details

Defined in Solkattu.Instrument.Sargam

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 
Instances
Eq Input # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Show Input # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty Input # 
Instance details

Defined in Perform.Pitch

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
Eq KbdType # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Show KbdType # 
Instance details

Defined in Perform.Pitch

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 # 
Instance details

Defined in Perform.Pitch

Fractional NoteNumber # 
Instance details

Defined in Perform.Pitch

Num NoteNumber # 
Instance details

Defined in Perform.Pitch

Ord NoteNumber # 
Instance details

Defined in Perform.Pitch

Read.Read NoteNumber # 
Instance details

Defined in Perform.Pitch

Real NoteNumber # 
Instance details

Defined in Perform.Pitch

RealFrac NoteNumber # 
Instance details

Defined in Perform.Pitch

Show NoteNumber # 
Instance details

Defined in Perform.Pitch

ApproxEq.ApproxEq NoteNumber # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty NoteNumber # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize NoteNumber # 
Instance details

Defined in Perform.Pitch

ShowVal.ShowVal NoteNumber # 
Instance details

Defined in Perform.Pitch

ToVal NoteNumber # 
Instance details

Defined in Derive.RestrictedEnviron

TypecheckNum NoteNumber # 
Instance details

Defined in Derive.Typecheck

ToVal NoteNumber # 
Instance details

Defined in Derive.Typecheck

Typecheck NoteNumber # 
Instance details

Defined in Derive.Typecheck

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

type Cent = Int 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

newtype ScaleId Source #

Constructors

ScaleId Text 
Instances
Eq ScaleId # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord ScaleId # 
Instance details

Defined in Perform.Pitch

Read.Read ScaleId # 
Instance details

Defined in Perform.Pitch

Show ScaleId # 
Instance details

Defined in Perform.Pitch

String.IsString ScaleId # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty ScaleId # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize ScaleId # 
Instance details

Defined in Perform.Pitch

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 # 
Instance details

Defined in Perform.Pitch

Ord Transpose # 
Instance details

Defined in Perform.Pitch

Show Transpose # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty Transpose # 
Instance details

Defined in Perform.Pitch

ShowVal.ShowVal Transpose # 
Instance details

Defined in Perform.Pitch

ToVal Transpose # 
Instance details

Defined in Derive.RestrictedEnviron

Methods

to_val :: Transpose -> Val Source #

TypecheckNum Transpose # 
Instance details

Defined in Derive.Typecheck

ToVal Transpose # 
Instance details

Defined in Derive.Typecheck

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.

Instance details

Defined in Derive.Typecheck

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
Eq Key # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Key # 
Instance details

Defined in Perform.Pitch

Methods

compare :: Key -> Key -> Ordering #

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

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

(>) :: Key -> Key -> Bool #

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

max :: Key -> Key -> Key #

min :: Key -> Key -> Key #

Read.Read Key # 
Instance details

Defined in Perform.Pitch

Show Key # 
Instance details

Defined in Perform.Pitch

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String.String #

showList :: [Key] -> ShowS #

Pretty.Pretty Key # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Key # 
Instance details

Defined in Perform.Pitch

ShowVal.ShowVal Key # 
Instance details

Defined in Perform.Pitch

Methods

show_val :: Key -> Text Source #