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

Derive.Deriver.Lib

Description

This has the higher level parts of the deriver library. That is, functions where are considered basic but can be defined outside of Derive.Deriver.Monad.

Synopsis

Documentation

data Result Source #

Package up the results of a derivation.

Constructors

Result 

Fields

derive :: Constant -> Dynamic -> Deriver a -> RunResult a Source #

Kick off a derivation.

errors

catch Source #

Arguments

:: Bool

If True, incorporate the evaluated state_collect. This is False for eval which is disconnected from track evaluation, and shouldn't be accumulating things like ControlMods.

-> Deriver a 
-> Deriver (Maybe.Maybe a) 

If the deriver throws, log the error and return Nothing.

state access

import

with_imported :: Bool -> Module.Module -> Deriver a -> Deriver a Source #

Merge calls from the given module into scope.

with_imported_symbols :: Module.Module -> Set Expr.Symbol -> Deriver a -> Deriver a Source #

Import only the given symbols from the module.

with_scopes :: (Scopes -> Scopes) -> Deriver a -> Deriver a Source #

Run the derivation with a modified scope.

scale

get_scale :: Pitch.ScaleId -> Deriver Scale Source #

Lookup a scale_id or throw.

environment

get_val :: Typecheck.Typecheck a => EnvKey.Key -> Deriver a Source #

Like lookup_val, but throw if the value isn't present.

with_val :: Typecheck.ToVal val => EnvKey.Key -> val -> Deriver a -> Deriver a Source #

Set the given val dynamically within the given computation. This is analogous to a dynamic let.

Remove on VNotGiven, which is what any Nothing will become. There's no use for a VNotGiven in the environ. The main way this is used is the val=_ c_equal syntax.

There is intentionally no way to modify the environment via assignment. It would introduce an order of execution dependency that would complicate caching as well as have a confusing non-local effect.

This dispatches to with_scale or with_instrument if it's setting the scale or instrument, so scale or instrument scopes are always set when scale and instrument are.

with_vals :: Typecheck.ToVal val => [(EnvKey.Key, val)] -> Deriver a -> Deriver a Source #

Like with_val, but should be slightly more efficient for setting multiple values at once.

with_environ :: DeriveT.Environ -> Deriver a -> Deriver a Source #

Merge the given environ into the environ in effect. Unlike with_val or with_vals, this won't set scopes for EnvKey.scale and EnvKey.instrument.

with_val_raw :: Typecheck.ToVal val => EnvKey.Key -> val -> Deriver a -> Deriver a Source #

Like with_val, but don't set scopes for instrument and scale. Also don't check for types, so you can replace a val with one of a different type. Due to this it's also more efficient.

with_scale :: Scale -> Deriver d -> Deriver d Source #

Replace the scale's calls.

Previously this used add_priority instead of replace_priority, which meant you could overlay scales and use both at the same time. Maybe that's actually a useful feature? In any case, I don't need it at the moment, so it seems more likely to be confusing than useful.

with_instrument :: ScoreT.Instrument -> Deriver d -> Deriver d Source #

Run the a deriver with the given instrument in scope. In addition to assigning the instrument to the EnvKey.instrument field where note calls can inherit it, this also brings the Instrument fields into scope, which is the per-instrument calls and per-instrument environ.

lookup_instrument :: ScoreT.Instrument -> Deriver (ScoreT.Instrument, Either.Either Text Instrument) Source #

Look up the instrument. Also return the instrument name after resolving any alias. This is what goes in Score.event_instrument, since it's what the performer understands.

control

control_at :: ScoreT.Control -> RealTime -> Deriver (Maybe.Maybe (ScoreT.Typed Signal.Y)) Source #

Get the control value at the given time.

controls_at :: RealTime -> Deriver ScoreT.ControlValMap Source #

Get a ControlValMap at the given time.

modify_signals :: (Signal.Control -> Signal.Control) -> (DeriveT.PSignal -> DeriveT.PSignal) -> Deriver a -> Deriver a Source #

Modify all VSignal and VPSignal types in environ.

control signal

remove_controls :: [ScoreT.Control] -> Deriver a -> Deriver a Source #

Remove both controls and control functions. Use this when a control has already been applied, and you don't want it to affect further derivation.

with_merged_control :: Merger -> ScoreT.Control -> ScoreT.Typed Signal.Control -> Deriver a -> Deriver a Source #

Modify the given control according to the Merger.

If both signals are typed, the existing type wins over the relative signal's type. If one is untyped, the typed one wins.

As documented in merge, this acts like a Set if there is no existing control.

with_merged_controls :: [(ScoreT.Control, ScoreT.Typed Signal.Control)] -> Deriver a -> Deriver a Source #

Like with_controls, but merge them with their respective default Mergers.

get_default_merger :: ScoreT.Control -> Deriver Merger Source #

Get the default merger for this control, or merge_mul if there is none.

ControlMod

eval_control_mods Source #

Arguments

:: RealTime

Trim controls to end at this time. If a ControlMod is local to a slice it should end when the slice ends, and since it bypasses trim_signal, I have to trim it explicitly.

-> Deriver a 
-> Deriver a 

Apply the collected control mods to the given deriver and clear them out.

pitch

pitch_at :: RealTime -> Deriver (Maybe.Maybe DeriveT.Pitch) Source #

The pitch at the given time. The transposition controls have not been applied since that is supposed to be done once only when the event is generated.

The scenario is a call that generates a note based on the current pitch. If pitch_at applied the transposition, the new note would have to remove the transposition signals so they don't get applied again at performance conversion.

resolve_pitch :: RealTime -> DeriveT.Pitch -> Deriver DeriveT.Transposed Source #

Resolve the raw pitch returned from pitch_at to the final transposed pitch.

nn_at :: RealTime -> Deriver (Maybe.Maybe Pitch.NoteNumber) Source #

Unlike pitch_at, the transposition has already been applied, because you can't transpose any further once you have a NoteNumber.

with signal

run monad

run_logs :: Log.LogId a -> Deriver a Source #

Embed a LogId into Deriver. This is for computations that need logging but not a full Deriver.

Mode

postproc

with_event_stack :: Score.Event -> Deriver a -> Deriver a Source #

Replace the state_stack with the one from the event. This is useful for transformers, so they can show a stack trace to the event they are processing.

shift_controls :: ScoreTime -> Deriver a -> Deriver a Source #

Shift the controls of a deriver. You're supposed to apply the warp before deriving the controls, but I don't have a good solution for how to do this yet, so I can leave these here for the moment.

call

val_call :: Typecheck.ToVal a => Module.Module -> CallName -> Tags.Tags -> Doc.Doc -> WithArgDoc (PassedArgs Tagged -> Deriver a) -> ValCall Source #

Wrap make_val_call with a Typecheck.to_val to automatically convert to a DeriveT.Val. This is not in Derive.Deriver.Monad to avoid a circular import with Derive.DeriveT.