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

Safe HaskellNone

Derive.Score

Contents

Description

This has the basic data structures for the deriver level.

The events here are generated from UI Events, and will eventually be transformed into Perform Events, which are specific to the performance backend.

Synopsis

Documentation

data ControlFunction Source #

Another representation of a signal, complementary to Signal.Control. It's more powerful because it has access to a subset of the Dynamic state, as well as the Control is was originally bound to. However, it's also less powerful because you can't inspect it to see if it's constant, or emit exactly the samples present without resorting to sampling, or draw it on the UI. This is the ubiquitous code vs. data tradeoff.

In addition, the main motivation to add control functions was to randomize values, which means that, unlike signals, they're not actually functions at all, and thus couldn't be rendered as a continuous signal. This means that functions are only suitable for sampling at points, not for slicing over time ranges.

Having both signals and functions is awkward because then some calls may ignore a control function if they require a signal, which is inconsistent and confusing. This is the case for all control generators since the signal usually is on a control track and will wind up being rendered on the UI. So the convention is that control functions are generally just modifications of an underlying signal, rather than synthesizing a signal.

Another awkward thing about ControlFunction is that it really wants to be in Deriver, but can't, due to circular imports. The alternative is a giant hs-boot file, or lumping thousands of lines into Derive.Deriver.Monad. Currently it's a plain function but if I want logging and exceptions I could use Derive.Deriver.DeriveM. It still wouldn't solve the main problem, which is that I can't reuse the Deriver functions, and instead have to rewrite them.

See NOTE [control-function].

Constructors

ControlFunction !Text !(Control -> BaseTypes.Dynamic -> RealTime -> Typed Signal.Y)

Control is the control name this function was bound to, if it was bound to one. Dynamic is a stripped down Derive State. For ControlFunctions that represent a control signal, the RealTime is the desired X value, otherwise it's just some number.

Event

data Event Source #

Constructors

Event 

Fields

Instances
Show Event # 
Instance details

Defined in Derive.Score

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

Show InstrumentCalls # 
Instance details

Defined in Derive.Deriver.Monad

Show Builtins # 
Instance details

Defined in Derive.Deriver.Monad

Show Library # 
Instance details

Defined in Derive.Library

Semigroup NoteDeriver # 
Instance details

Defined in Derive.Deriver.Monad

Monoid NoteDeriver # 
Instance details

Defined in Derive.Deriver.Monad

DeepSeq.NFData Event # 
Instance details

Defined in Derive.Score

Methods

rnf :: Event -> () #

Pretty.Pretty Event # 
Instance details

Defined in Derive.Score

Taggable Event # 
Instance details

Defined in Derive.Deriver.Monad

Cacheable Event # 
Instance details

Defined in Derive.Cache

Semigroup (Stream Event) # 
Instance details

Defined in Derive.Stream

Monoid (Stream Event) # 
Instance details

Defined in Derive.Stream

Callable (Transformer Note) # 
Instance details

Defined in Derive.Deriver.Monad

Callable (Generator Note) # 
Instance details

Defined in Derive.Deriver.Monad

Callable (TrackCall Note) # 
Instance details

Defined in Derive.Deriver.Monad

ToLibrary (Transformer Note) # 
Instance details

Defined in Derive.Library

ToLibrary (Generator Note) # 
Instance details

Defined in Derive.Library

ToLibrary (TrackCall Note) # 
Instance details

Defined in Derive.Library

short_event :: Event -> Text Source #

Format an event in a way suitable for including inline in log messages. It's short, but hopefully enough information to identify the event in question.

This is the derive equivalent to log_event.

event_min :: Event -> RealTime Source #

Get minimum and maximum edges of the event. event_start isn't necessarily the minimum because of negative durations.

event_max :: Event -> RealTime Source #

Get minimum and maximum edges of the event. event_start isn't necessarily the minimum because of negative durations.

copy :: Event -> Event Source #

If you use an event to create another event, call this to clear out data that shouldn't go with the copy.

normalize :: Event -> Event Source #

Apply environ and controls to pitches.

Normally this is done by Convert, but if you want to see an event for debugging it can be nicer to see the normalized version.

Unlike Perform.Midi.Convert, this doesn't trim the controls, so it applies out-of-range transpositions.

flags

logs

environ

modify_environ_key :: EnvKey.Key -> (Maybe BaseTypes.Val -> BaseTypes.Val) -> Event -> Event Source #

Modify the value at the given key.

attributes

delayed args

put_arg :: Typeable a => Text -> a -> Event -> Event Source #

take_arg :: Typeable a => Text -> Event -> Either Text (Event, Maybe a) Source #

Find an arg in event_delayed_args, and remove it from the event if it existed. Throw an error if it existed but had an unexpected type.

modify events

move :: (RealTime -> RealTime) -> Event -> Event Source #

Change the start time of an event and move its controls along with it.

set_instrument :: Instrument -> BaseTypes.Environ -> Event -> Event Source #

Set the instrument on an event, and also update its environ from the instrument. You should really rederive with the new instrument, but this way can be more convenient, if somewhat sketchy.

control

data Control Source #

A control is an abstract parameter that influences derivation. Some of them affect performance and will be rendered as MIDI controls or note parameters or whatever, while others may affect derivation (e.g. tempo) and won't be seen by the backend at all.

A Control should be a valid identifier as defined by valid_symbol.

Instances
Eq Control # 
Instance details

Defined in Derive.ScoreTypes

Methods

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

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

Ord Control # 
Instance details

Defined in Derive.ScoreTypes

Read Control # 
Instance details

Defined in Derive.ScoreTypes

Show Control # 
Instance details

Defined in Derive.ScoreTypes

IsString Control # 
Instance details

Defined in Derive.ScoreTypes

Methods

fromString :: String -> Control #

DeepSeq.NFData Control # 
Instance details

Defined in Derive.ScoreTypes

Methods

rnf :: Control -> () #

Pretty.Pretty Control # 
Instance details

Defined in Derive.ScoreTypes

Pretty.Pretty BaseTypes.ControlRef # 
Instance details

Defined in Derive.BaseTypes

Serialize Control # 
Instance details

Defined in Derive.ScoreTypes

ShowVal Control # 
Instance details

Defined in Derive.ScoreTypes

ShowVal BaseTypes.ControlRef #

This can only represent constant signals, since there's no literal for an arbitrary signal. Non-constant signals will turn into a constant of whatever was at 0.

Instance details

Defined in Derive.BaseTypes

ToVal BaseTypes.ControlRef # 
Instance details

Defined in Derive.RestrictedEnviron

ToVal Control # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.ControlRef # 
Instance details

Defined in Derive.Typecheck

Typecheck Control # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.ControlRef #

Use a TypedFunction or Function instead of this.

Instance details

Defined in Derive.Typecheck

ShowVal (Typed Control) # 
Instance details

Defined in Derive.ScoreTypes

type ControlValMap = Map Control Signal.Y Source #

This is a snapshot of the control signals at a certain point in time. It's meant for PitchConfig, so the values are expected to be transpositions, and hence untyped.

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

Get a control value from the event, or Nothing if that control isn't present.

modify_dynamic :: (Signal.Y -> Signal.Y) -> Event -> Event Source #

Use this instead of modify_control_vals because it also sets EnvKey.dynamic_val. This is only valid for linear functions like (+) or (*).

set_dynamic :: Signal.Y -> Event -> Event Source #

Use this instead of set_control because it also sets EnvKey.dynamic_val.

modify_control :: Control -> (Signal.Control -> Signal.Control) -> Event -> Event Source #

Modify a control. If there is no existing control, the modify function gets an empty signal.

pitch

data PControl Source #

The pitch control version of Control. Unlike Control, this is allowed to be null, which is the name of the default pitch signal.

A PControl should be a valid identifier as defined by valid_symbol, except that its literal tracklang form starts with a #, to differentiate from a Control.

Instances
Eq PControl # 
Instance details

Defined in Derive.ScoreTypes

Ord PControl # 
Instance details

Defined in Derive.ScoreTypes

Read PControl # 
Instance details

Defined in Derive.ScoreTypes

Show PControl # 
Instance details

Defined in Derive.ScoreTypes

IsString PControl # 
Instance details

Defined in Derive.ScoreTypes

DeepSeq.NFData PControl # 
Instance details

Defined in Derive.ScoreTypes

Methods

rnf :: PControl -> () #

Pretty.Pretty PControl # 
Instance details

Defined in Derive.ScoreTypes

Pretty.Pretty BaseTypes.PControlRef # 
Instance details

Defined in Derive.BaseTypes

Serialize PControl # 
Instance details

Defined in Derive.ScoreTypes

ShowVal PControl # 
Instance details

Defined in Derive.ScoreTypes

ShowVal BaseTypes.PControlRef #

There's no way to convert a pitch back into the expression that produced it, so this is the best I can do.

Similar to ShowVal BaseTypes.ControlRef, there's no signal literal so I use the value at 0. A pitch can be turned into an expression, but not necessarily accurately since it doesn't take things like pitch interpolation into account.

Instance details

Defined in Derive.BaseTypes

ToVal PControl # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.PControlRef # 
Instance details

Defined in Derive.Typecheck

Typecheck PControl # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.PControlRef # 
Instance details

Defined in Derive.Typecheck

transposed_at :: RealTime -> Event -> Maybe BaseTypes.Transposed Source #

Unlike pitch_at, the transposition has already been applied. This is because callers expect to get the actual pitch, not the pitch plus some homework to do on the pitch. If you use this pitch to emit another pitch you proabbly need the raw pitch, but so far everyone doing that is at the Derive level, not postproc, so they use Derive.pitch_at.

Type

data Type Source #

Tag for the type of the values in a control signal.

Constructors

Untyped 
Chromatic 
Diatonic 
Nn 
Score 
Real 
Instances
Enum Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

succ :: Type -> Type #

pred :: Type -> Type #

toEnum :: Int -> Type #

fromEnum :: Type -> Int #

enumFrom :: Type -> [Type] #

enumFromThen :: Type -> Type -> [Type] #

enumFromTo :: Type -> Type -> [Type] #

enumFromThenTo :: Type -> Type -> Type -> [Type] #

Eq Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

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

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

Ord Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

compare :: Type -> Type -> Ordering #

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

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

(>) :: Type -> Type -> Bool #

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

max :: Type -> Type -> Type #

min :: Type -> Type -> Type #

Read Type # 
Instance details

Defined in Derive.ScoreTypes

Show Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

Semigroup Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

(<>) :: Type -> Type -> Type #

sconcat :: NonEmpty Type -> Type #

stimes :: Integral b => b -> Type -> Type #

Monoid Type # 
Instance details

Defined in Derive.ScoreTypes

Methods

mempty :: Type #

mappend :: Type -> Type -> Type #

mconcat :: [Type] -> Type #

Pretty.Pretty Type # 
Instance details

Defined in Derive.ScoreTypes

Serialize Type # 
Instance details

Defined in Derive.ScoreTypes

data Typed a Source #

Constructors

Typed 

Fields

Instances
Functor Typed # 
Instance details

Defined in Derive.ScoreTypes

Methods

fmap :: (a -> b) -> Typed a -> Typed b #

(<$) :: a -> Typed b -> Typed a #

Pretty.Pretty BaseTypes.ControlRef # 
Instance details

Defined in Derive.BaseTypes

ShowVal BaseTypes.ControlRef #

This can only represent constant signals, since there's no literal for an arbitrary signal. Non-constant signals will turn into a constant of whatever was at 0.

Instance details

Defined in Derive.BaseTypes

ShowVal TypedFunction # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.ControlRef # 
Instance details

Defined in Derive.RestrictedEnviron

ToVal BaseTypes.ControlRef # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.ControlRef #

Use a TypedFunction or Function instead of this.

Instance details

Defined in Derive.Typecheck

Typecheck TypedFunction # 
Instance details

Defined in Derive.Typecheck

Eq a => Eq (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

(==) :: Typed a -> Typed a -> Bool #

(/=) :: Typed a -> Typed a -> Bool #

Ord a => Ord (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

compare :: Typed a -> Typed a -> Ordering #

(<) :: Typed a -> Typed a -> Bool #

(<=) :: Typed a -> Typed a -> Bool #

(>) :: Typed a -> Typed a -> Bool #

(>=) :: Typed a -> Typed a -> Bool #

max :: Typed a -> Typed a -> Typed a #

min :: Typed a -> Typed a -> Typed a #

Read a => Read (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Show a => Show (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

showsPrec :: Int -> Typed a -> ShowS #

show :: Typed a -> String #

showList :: [Typed a] -> ShowS #

Semigroup a => Semigroup (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

(<>) :: Typed a -> Typed a -> Typed a #

sconcat :: NonEmpty (Typed a) -> Typed a #

stimes :: Integral b => b -> Typed a -> Typed a #

(Semigroup a, Monoid a) => Monoid (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

mempty :: Typed a #

mappend :: Typed a -> Typed a -> Typed a #

mconcat :: [Typed a] -> Typed a #

DeepSeq.NFData a => DeepSeq.NFData (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

rnf :: Typed a -> () #

Pretty.Pretty a => Pretty.Pretty (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Serialize a => Serialize (Typed a) # 
Instance details

Defined in Derive.ScoreTypes

Methods

put :: Putter (Typed a) Source #

get :: Get (Typed a) Source #

ShowVal (Typed Signal.Y) # 
Instance details

Defined in Derive.ScoreTypes

ShowVal (Typed Control) # 
Instance details

Defined in Derive.ScoreTypes

TypecheckNum (Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

ToVal (Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

Typecheck (Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

untyped :: a -> Typed a Source #

merge_typed :: (a -> a -> a) -> Typed a -> Typed a -> Typed a Source #

instrument

newtype Instrument Source #

An Instrument is identified by a plain string. This will be looked up in the instrument db to get the backend specific Instrument type as well as the backend itself, but things at the Derive layer and above don't care about all that.

This should be a valid symbol as defined by valid_symbol. This way it can be parsed without quotes.

Constructors

Instrument Text 
Instances
Eq Instrument # 
Instance details

Defined in Derive.ScoreTypes

Ord Instrument # 
Instance details

Defined in Derive.ScoreTypes

Read Instrument # 
Instance details

Defined in Derive.ScoreTypes

Show Instrument # 
Instance details

Defined in Derive.ScoreTypes

IsString Instrument # 
Instance details

Defined in Derive.ScoreTypes

DeepSeq.NFData Instrument # 
Instance details

Defined in Derive.ScoreTypes

Methods

rnf :: Instrument -> () #

Pretty.Pretty Instrument # 
Instance details

Defined in Derive.ScoreTypes

Serialize Instrument # 
Instance details

Defined in Derive.ScoreTypes

ShowVal Instrument # 
Instance details

Defined in Derive.ScoreTypes

ToVal Instrument # 
Instance details

Defined in Derive.RestrictedEnviron

ToVal Instrument # 
Instance details

Defined in Derive.Typecheck

Typecheck Instrument # 
Instance details

Defined in Derive.Typecheck

util

control :: Text -> Either Text Control Source #

Use this constructor when making a Control from user input. Literals can use the IsString instance.

pcontrol :: Text -> Either Text PControl Source #

Use this constructor when making a PControl from user input. Literals can use the IsString instance.

c_dynamic :: Control Source #

Converted into velocity or breath depending on the instrument.

parse_generic_control :: Text -> Either Text (Either Control PControl) Source #

Parse either a Control or PControl.