Safe Haskell | Safe-Inferred |
---|
Utilities for simple scales, which simply map pitch names to frequencies.
Ok, so they also have octave structure, used by the input mechanism and to
parse to Pitch.Pitch
es, but it can be set to the number of degrees in the
scale if you don't have octaves.
Synopsis
- make_scale :: Pitch.ScaleId -> DegreeMap -> Text -> Doc.Doc -> Scale
- empty_scale :: Pitch.ScaleId -> Text -> DocumentedCall -> Scale
- data DegreeMap = DegreeMap {}
- degree_map :: Pitch.PitchClass -> Pitch.Octave -> Pitch.PitchClass -> [Pitch.Note] -> [Pitch.NoteNumber] -> DegreeMap
- type SemisToNoteNumber = DeriveT.PitchConfig -> Pitch.Semi -> Either DeriveT.PitchError Pitch.NoteNumber
- read_note :: DegreeMap -> Pitch.Note -> Either DeriveT.PitchError Pitch.Pitch
- show_pitch :: DegreeMap -> Pitch.Pitch -> Either DeriveT.PitchError Pitch.Note
- transpose :: DegreeMap -> Transpose
- non_transposing :: Transpose
- standard_transposers :: Set ScoreT.Control
- mapped_note_to_call :: DegreeMap -> DeriveT.Scale -> Pitch.Note -> Maybe.Maybe ValCall
- note_to_call :: Pitch.Semi -> Maybe.Maybe Pitch.Semi -> DeriveT.Scale -> SemisToNoteNumber -> (Pitch.Semi -> Maybe.Maybe Pitch.Note) -> ValCall
- add_pc :: DegreeMap -> Pitch.PitchClass -> Pitch.Pitch -> Pitch.Pitch
- type InputToNote = DeriveT.Environ -> Pitch.Input -> Either DeriveT.PitchError Pitch.Note
- input_to_note :: DegreeMap -> InputToNote
- type InputToNn = ScoreTime -> Pitch.Input -> Deriver (Either DeriveT.PitchError Pitch.NoteNumber)
- mapped_input_to_nn :: DegreeMap -> InputToNn
- set_direct_input_to_nn :: Scale -> Scale
- direct_input_to_nn :: InputToNn
- computed_input_to_nn :: InputToNote -> (Pitch.Note -> Maybe.Maybe ValCall) -> InputToNn
- make_nn :: Maybe.Maybe Pitch.NoteNumber -> Pitch.NoteNumber -> Maybe.Maybe Pitch.NoteNumber -> Pitch.Frac -> Maybe.Maybe Pitch.NoteNumber
- simple_kbd_to_scale :: DegreeMap -> Pitch.KbdType -> Pitch.Pitch -> Either DeriveT.PitchError Pitch.Semi
- pitch_to_semis :: DegreeMap -> Pitch.Pitch -> Pitch.Semi
- semis_to_pitch :: DegreeMap -> Pitch.Semi -> Pitch.Pitch
- kbd_to_scale :: Pitch.KbdType -> Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Either DeriveT.PitchError Pitch.Pitch
- lookup_kbd_to_scale :: Pitch.KbdType -> Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Maybe.Maybe Pitch.Pitch
- piano_kbd_pitch :: Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Maybe.Maybe Pitch.Pitch
- ascii_kbd_pitch :: Pitch.PitchClass -> Pitch.Pitch -> Pitch.Pitch
- adjust_octave :: Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Octave -> Pitch.PitchClass -> (Pitch.Octave, Pitch.PitchClass)
- call_doc :: Set ScoreT.Control -> DegreeMap -> Doc.Doc -> DocumentedCall
- default_scale_degree_doc :: DocumentedCall
- scale_degree_doc :: (DeriveT.Scale -> Scale.PitchNn -> Scale.PitchNote -> ValCall) -> DocumentedCall
- annotate_call_doc :: Set ScoreT.Control -> Doc.Doc -> [(Doc.Doc, Doc.Doc)] -> DocumentedCall -> DocumentedCall
- add_doc :: Doc.Doc -> Scale -> Scale
- prepend_doc :: Doc.Doc -> DocumentedCall -> DocumentedCall
- modify_doc :: (Doc.Doc -> Doc.Doc) -> DocumentedCall -> DocumentedCall
- no_enharmonics :: Enharmonics
- read_environ :: (Typecheck.Typecheck a, ShowVal.ShowVal a) => (a -> Maybe.Maybe val) -> Maybe.Maybe val -> EnvKey.Key -> DeriveT.Environ -> Either DeriveT.PitchError val
- read_environ_default :: (Typecheck.Typecheck a, ShowVal.ShowVal a) => (a -> Maybe.Maybe val) -> Maybe.Maybe a -> EnvKey.Key -> DeriveT.Environ -> Either DeriveT.PitchError val
- read_environ_ :: (Typecheck.Typecheck a, ShowVal.ShowVal a) => (a -> Either (Maybe.Maybe Text) val) -> Maybe.Maybe (Either DeriveT.PitchError val) -> EnvKey.Key -> DeriveT.Environ -> Either DeriveT.PitchError val
- environ_key :: DeriveT.Environ -> Maybe.Maybe Pitch.Key
- get_key :: key -> Map Pitch.Key key -> Maybe.Maybe Pitch.Key -> Either DeriveT.PitchError key
- lookup_key :: key -> Map Pitch.Key key -> Maybe.Maybe Pitch.Key -> Maybe.Maybe key
- key_error :: Pitch.Key -> DeriveT.PitchError
Documentation
make_scale :: Pitch.ScaleId -> DegreeMap -> Text -> Doc.Doc -> Scale Source #
Make a simple scale where there is a direct mapping from input to note to nn.
empty_scale :: Pitch.ScaleId -> Text -> DocumentedCall -> Scale Source #
An empty scale that doesn't do anything.
types
DegreeMap | |
|
:: Pitch.PitchClass | |
-> Pitch.Octave | The first Note is this Octave and PitchClass. |
-> Pitch.PitchClass | |
-> [Pitch.Note] | |
-> [Pitch.NoteNumber] | |
-> DegreeMap |
type SemisToNoteNumber = DeriveT.PitchConfig -> Pitch.Semi -> Either DeriveT.PitchError Pitch.NoteNumber Source #
scale functions
transpose
non_transposing :: Transpose Source #
Transpose function for a non-transposing scale.
standard_transposers :: Set ScoreT.Control Source #
Indicate that this scale responds to the standard set of transpose
signals. It still has to implement the support in its
scale_note_to_call
.
note_to_call
mapped_note_to_call :: DegreeMap -> DeriveT.Scale -> Pitch.Note -> Maybe.Maybe ValCall Source #
A specialization of note_to_call
that operates on scales with
a DegreeMap
, i.e. a static map from notes to degrees, and from degrees to
NNs.
note_to_call :: Pitch.Semi -> Maybe.Maybe Pitch.Semi -> DeriveT.Scale -> SemisToNoteNumber -> (Pitch.Semi -> Maybe.Maybe Pitch.Note) -> ValCall Source #
Create a note call that respects chromatic and diatonic transposition. However, diatonic transposition is mapped to chromatic transposition, so this is for scales that don't distinguish.
add_pc :: DegreeMap -> Pitch.PitchClass -> Pitch.Pitch -> Pitch.Pitch Source #
input
type InputToNote = DeriveT.Environ -> Pitch.Input -> Either DeriveT.PitchError Pitch.Note Source #
input_to_note :: DegreeMap -> InputToNote Source #
Input to note for simple scales without keys.
type InputToNn = ScoreTime -> Pitch.Input -> Deriver (Either DeriveT.PitchError Pitch.NoteNumber) Source #
mapped_input_to_nn :: DegreeMap -> InputToNn Source #
Input to NoteNumber for scales that have a direct relationship between Degree and NoteNumber.
set_direct_input_to_nn :: Scale -> Scale Source #
direct_input_to_nn :: InputToNn Source #
An Input maps directly to a NoteNumber. This is an efficient implementation for scales tuned to 12TET.
This obeys Controls.octave
but none of the other transposer controls.
This is inconsistent with computed_input_to_nn
, but trying to implement
diatonic transposition would make this not so direct any more. And in
any case, Cmd.MidiThru shouldn't let through any transposers other than
octave.
computed_input_to_nn :: InputToNote -> (Pitch.Note -> Maybe.Maybe ValCall) -> InputToNn Source #
Convert input to nn by going through note_to_call. This works for complicated scales that retune based on the environment but is more work.
make_nn :: Maybe.Maybe Pitch.NoteNumber -> Pitch.NoteNumber -> Maybe.Maybe Pitch.NoteNumber -> Pitch.Frac -> Maybe.Maybe Pitch.NoteNumber Source #
diatonic
simple_kbd_to_scale :: DegreeMap -> Pitch.KbdType -> Pitch.Pitch -> Either DeriveT.PitchError Pitch.Semi Source #
pitch_to_semis :: DegreeMap -> Pitch.Pitch -> Pitch.Semi Source #
semis_to_pitch :: DegreeMap -> Pitch.Semi -> Pitch.Pitch Source #
kbd_to_scale :: Pitch.KbdType -> Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Either DeriveT.PitchError Pitch.Pitch Source #
lookup_kbd_to_scale :: Pitch.KbdType -> Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Maybe.Maybe Pitch.Pitch Source #
Convert an absolute Pitch in the input keyboard's layout to a relative Pitch within a scale with the given number of diatonic steps per octave, or Nothing if that key should have no pitch.
piano_kbd_pitch :: Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Pitch -> Maybe.Maybe Pitch.Pitch Source #
The MIDI kbd is absolute. This means that relative scales start on different keys rather than all starting on C. For example, in C major C produces the first scale degree, while in D major D produces the first scale degree.
In addition, if the scale octave is not an even multiple of the kbd octave (7), the extra notes produce Nothing. This check has to be done to the relative PitchClass. That way, a D on a 6 note scale starting on D is 1, and a C is Nothing. Thus, the returned Pitch is relative to the given tonic, so it should be formatted as-is, without the key.
ascii_kbd_pitch :: Pitch.PitchClass -> Pitch.Pitch -> Pitch.Pitch Source #
The ASCII kbd is relative. This means that relative scales always start
on "C". So the tonic note of a key in a relative scale is irrelevant,
C major and D major both start in the same place. Of course, they produce
different frequencies, but that's the responsibility of
scale_note_to_call
.
Unlike absolute_to_pitch
, if the scale octave is not an even multiple of
the kbd octave (10), the extra notes wrap to the next highest octave.
adjust_octave :: Pitch.PitchClass -> Pitch.PitchClass -> Pitch.Octave -> Pitch.PitchClass -> (Pitch.Octave, Pitch.PitchClass) Source #
Try to fit a note from a keyboard into a scale. Round the note up to the nearest multiple of the keyboard octave and adjust the octave accordingly.
call_doc
call_doc :: Set ScoreT.Control -> DegreeMap -> Doc.Doc -> DocumentedCall Source #
default_scale_degree_doc :: DocumentedCall Source #
Documentation of the standard scale_degree
.
scale_degree_doc :: (DeriveT.Scale -> Scale.PitchNn -> Scale.PitchNote -> ValCall) -> DocumentedCall Source #
annotate_call_doc :: Set ScoreT.Control -> Doc.Doc -> [(Doc.Doc, Doc.Doc)] -> DocumentedCall -> DocumentedCall Source #
DocumentedCall
prepend_doc :: Doc.Doc -> DocumentedCall -> DocumentedCall Source #
Prepend a bit of text to the documentation.
modify_doc :: (Doc.Doc -> Doc.Doc) -> DocumentedCall -> DocumentedCall Source #
util
:: (Typecheck.Typecheck a, ShowVal.ShowVal a) | |
=> (a -> Maybe.Maybe val) | |
-> Maybe.Maybe val | if Just, a missing value gets this, otherwise error |
-> EnvKey.Key | |
-> DeriveT.Environ | |
-> Either DeriveT.PitchError val |
Like read_environ_
, but with a simpler parser.
read_environ_default :: (Typecheck.Typecheck a, ShowVal.ShowVal a) => (a -> Maybe.Maybe val) -> Maybe.Maybe a -> EnvKey.Key -> DeriveT.Environ -> Either DeriveT.PitchError val Source #
Like read_environ
, except the default is given to the parse function.
read_environ_ :: (Typecheck.Typecheck a, ShowVal.ShowVal a) => (a -> Either (Maybe.Maybe Text) val) -> Maybe.Maybe (Either DeriveT.PitchError val) -> EnvKey.Key -> DeriveT.Environ -> Either DeriveT.PitchError val Source #
Read and parse an environ value, or throw a ScaleError. This takes a parse function in addition to the usual Typecheck, because scales and keys don't use use Typecheck, beyond ensuring it's a string.
keys
get_key :: key -> Map Pitch.Key key -> Maybe.Maybe Pitch.Key -> Either DeriveT.PitchError key Source #
Find a key in a map, or throw a ScaleError.
lookup_key :: key -> Map Pitch.Key key -> Maybe.Maybe Pitch.Key -> Maybe.Maybe key Source #