Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Perform.Pitch

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

Instances details
String.IsString Note Source # 
Instance details

Defined in Perform.Pitch

Show Note Source # 
Instance details

Defined in Perform.Pitch

Eq Note Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Note Source # 
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 #

Pretty.Pretty Note Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Note Source # 
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

Instances details
Read.Read Pitch Source # 
Instance details

Defined in Perform.Pitch

Show Pitch Source # 
Instance details

Defined in Perform.Pitch

Eq Pitch Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Pitch Source # 
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 #

ToVal Pitch Source # 
Instance details

Defined in Derive.REnv

Methods

to_val :: Pitch -> Val Source #

ShowVal.ShowVal Pitch Source #

This relies on the presence of a pitch val call.

Instance details

Defined in Perform.Pitch

Methods

show_val :: Pitch -> Text Source #

ToVal Pitch Source # 
Instance details

Defined in Derive.Typecheck

Methods

to_val :: Pitch -> Val Source #

Typecheck Pitch Source # 
Instance details

Defined in Derive.Typecheck

Notation Pitch Source # 
Instance details

Defined in Solkattu.Instrument.Sargam

Pretty.Pretty Pitch Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Pitch Source # 
Instance details

Defined in Perform.Pitch

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

data Degree Source #

A scale degree, without reference to an octave.

Constructors

Degree 

Fields

Instances

Instances details
Read.Read Degree Source # 
Instance details

Defined in Perform.Pitch

Show Degree Source # 
Instance details

Defined in Perform.Pitch

Eq Degree Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Degree Source # 
Instance details

Defined in Perform.Pitch

Notation Degree Source # 
Instance details

Defined in Solkattu.Instrument.Sargam

Pretty.Pretty Degree Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Degree Source # 
Instance details

Defined in Perform.Pitch

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

Instances details
Show Input Source # 
Instance details

Defined in Perform.Pitch

Eq Input Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Pretty.Pretty Input Source # 
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

Instances details
Show KbdType Source # 
Instance details

Defined in Perform.Pitch

Eq KbdType Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

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

Instances details
Num NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Read.Read NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Fractional NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Real NoteNumber Source # 
Instance details

Defined in Perform.Pitch

RealFrac NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Show NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Eq NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Ord NoteNumber Source # 
Instance details

Defined in Perform.Pitch

ToVal NoteNumber Source # 
Instance details

Defined in Derive.REnv

ShowVal.ShowVal NoteNumber Source # 
Instance details

Defined in Perform.Pitch

ToVal NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

Typecheck NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

Pretty.Pretty NoteNumber Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize NoteNumber Source # 
Instance details

Defined in Perform.Pitch

ApproxEq.ApproxEq NoteNumber Source # 
Instance details

Defined in Perform.Pitch

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

Instances details
String.IsString ScaleId Source # 
Instance details

Defined in Perform.Pitch

Read.Read ScaleId Source # 
Instance details

Defined in Perform.Pitch

Show ScaleId Source # 
Instance details

Defined in Perform.Pitch

Eq ScaleId Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord ScaleId Source # 
Instance details

Defined in Perform.Pitch

Pretty.Pretty ScaleId Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize ScaleId Source # 
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

Instances details
Show Transpose Source # 
Instance details

Defined in Perform.Pitch

Eq Transpose Source # 
Instance details

Defined in Perform.Pitch

Ord Transpose Source # 
Instance details

Defined in Perform.Pitch

ToVal Transpose Source # 
Instance details

Defined in Derive.REnv

Methods

to_val :: Transpose -> Val Source #

ShowVal.ShowVal Transpose Source # 
Instance details

Defined in Perform.Pitch

ToVal Transpose Source # 
Instance details

Defined in Derive.Typecheck

Methods

to_val :: Transpose -> Val Source #

Typecheck Transpose Source #

VSignals 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

TypecheckNum Transpose Source # 
Instance details

Defined in Derive.Typecheck

Pretty.Pretty Transpose Source # 
Instance details

Defined in Perform.Pitch

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

Instances details
Read.Read Key Source # 
Instance details

Defined in Perform.Pitch

Show Key Source # 
Instance details

Defined in Perform.Pitch

Methods

showsPrec :: Int -> Key -> ShowS #

show :: Key -> String.String #

showList :: [Key] -> ShowS #

Eq Key Source # 
Instance details

Defined in Perform.Pitch

Methods

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

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

Ord Key Source # 
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 #

ShowVal.ShowVal Key Source # 
Instance details

Defined in Perform.Pitch

Methods

show_val :: Key -> Text Source #

Pretty.Pretty Key Source # 
Instance details

Defined in Perform.Pitch

Serialize.Serialize Key Source # 
Instance details

Defined in Perform.Pitch