Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone




This module defines basic tracklang types.

They all have to pretty much be here to avoid circular imports. But to avoid this module becoming even larger than it already is, subsets are re-exported from Derive.Score and Derive.PSignal. PSignal is types related directly to pitches. Score is for types required for Event. There is a third subset, which is types related to Val, which used to be re-exported from a TrackLang module, but are now intended to be imported directly from here. I eventually got rid of TrackLang because it just added a few small utilities but no additional dependencies, and since modules started directly using BaseTypes anyway to avoid dependencies. Many Score types are further divided into Derive.ScoreTypes, once again to avoid circular imports.

Perhaps the simplest would be to get rid of all the re-export guff.

Here are the names for various aspects of signals:

          numbers                   pitches                 both
scalar    Signal.Y                  PSignal.Y
name      Score.Control             Score.PControl
signal    Signal.Control            PSignal.PSignal
ref       BaseTypes.ControlRef      BaseTypes.PControlRef   Ref



newtype PSignal Source #

A pitch signal is similar to a Signal.Control, except that its values are Pitches instead of plain floating point values.




Show PSignal # 
Monoid PSignal # 
DeepSeq.NFData PSignal # 


rnf :: PSignal -> () #

Pretty.Pretty PControlRef # 
Pretty.Pretty PSignal # 
ShowVal.ShowVal 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 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.

Taggable Pitch # 
Callable PSignal # 
ToVal PControlRef # 
Typecheck PControlRef # 
Cacheable PSignal # 
Monoid (Stream PSignal) # 

type Pitch = RawPitch Untransposed_ Source #

This is an untransposed pitch. All pitches have transposition signals from the dynamic state applied when they are converted to MIDI or whatever backend. So if I want the final concrete pitch, I have to apply the transposition signals. But if I want to emit a note with this pitch, I want the untransposed one, or the transposition will be applied twice. I use a phantom type parameter to keep them straight.

type Transposed = RawPitch Transposed_ Source #

The transposed version of Pitch.

data RawPitch a Source #

A pitch is an abstract value that can generate a Pitch.NoteNumber or symbolic Pitch.Note.


ToVal Pitch # 


to_val :: Pitch -> Val Source #

Typecheck Pitch # 
Show (RawPitch a) # 


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

show :: RawPitch a -> String #

showList :: [RawPitch a] -> ShowS #

DeepSeq.NFData (RawPitch a) #

It can't be reduced since it has lambdas, but at least this way you can easily rnf things that contain it.


rnf :: RawPitch a -> () #

Pretty.Pretty (RawPitch a) #

Will look like: 62.95nn,4i(*wayang)

ShowVal.ShowVal (RawPitch a) #

Pitches have no literal syntax, but I have to print something.


show_val :: RawPitch a -> Text Source #

pitch_nn :: Transposed -> Either PitchError Pitch.NoteNumber Source #

Usually I only want to evaluate a fully transposed pitch. Exceptions are documented by applying coerce.

pitch_note :: Transposed -> Either PitchError Pitch.Note Source #

Usually I only want to evaluate a fully transposed pitch. Exceptions are documented by applying coerce.

data PitchConfig Source #

A PitchConfig is the data that can continue to influence the pitch's frequency.

Pitches are configured by controls and by an environ. The controls are for values that change over time, such as transposition or tuning. They're combined additively, which is really only appropriate for transposition. Controls are mostly applied only on conversion to the performer. TODO I don't entirely remember why. However, this leads to some trickiness because if I want to compare a pitch to an absolute NoteNumber, I need the final transposed value, but if I put it in an event it must be untransposed, or transposition will be applied twice. To avoid double. To avoid this, there's a phantom type parameter to distinguish an untransposed Pitch from a Transposed one.

The Environ is for symbolic configuration, such as key or tuning mode. Unlike controls, though, it's taken from the environ in scope when the pith is created. Otherwise, you can't evaluate a pitch with a different key by setting the environ.

data Scale Source #

PSignal can't take a Scale because that would be a circular import. Fortunately it only needs a few fields. However, because of the circularity, the Scale.Scale -> PSignal.Scale constructor is in Derive.Derive.




  • pscale_scale_id :: !Pitch.ScaleId

    It can be useful to see the scale of a pitch, e.g. to create more pitches in the same scale as an existing pitch.

  • pscale_transposers :: !(Set ScoreTypes.Control)

    The set of transposer signals for this scale, as documented in scale_transposers.

    They are stored here because they're needed by to_nn. I could store them separately, e.g. in the Event alongside the event_pitch, but the scale at event creation time is not guaranteed to be the same as the one when the pitch was created, so the safest thing to do is keep it with the pitch itself.

data PitchError Source #

Things that can go wrong evaluating a pitch.


OutOfRange !(Maybe Pitch.NoteNumber) !ScoreTypes.ControlValMap

Note out of the scale's range. The values are transpositions from the environment, in case it was out of range because of a transposition.

Some scales have a restricted range, in which case they should throw out_of_range, which pitch_nn and pitch_note will annotate with the transposition signals. Other scales have unlimited range, in which case they're limited by the backend. In this case pitch_nn checks 0--127, which happens to be MIDI's limitation.


Input note doesn't map to a scale note.

EnvironError !Key !Text

A required environ value was missing or had the wrong type or value. The Text is a ShowVal.show_val of the wrong Val.

ControlError !ScoreTypes.Control !Text

Same as EnvironError, but for control vals.


The scale doesn't implement that operation.

PitchError !Text

Other kind of error.


multiply_duration :: Duration -> Double -> Duration Source #

Duration can't be in Fractional since you can't multiple a RealDuration by a ScoreDuration, but scaling operations are still useful.


insert :: Key -> Val -> Environ -> Environ Source #

Insert a val directly, with no typechecking.

type Key = Expr.Str Source #

Symbols to look up a val in the ValMap.


data Val Source #

This is the type of first class values in the tracklang. It's main purpose is the type for arguments to tracklang calls, and val calls' return type.


VNum !ScoreTypes.TypedVal

A number with an optional type suffix. It also has a ratio style literal, though the output is still a floating point value, not a true ratio.

Literal: 42.23, -.4, 1c, -2.4d, 3/2, -3/2, 0x7f.

VAttributes !Attrs.Attributes

A set of Attributes for an instrument.

Literal: +attr, +attr1+attr2.

VControlRef !ControlRef

A control name. An optional value gives a default if the control isn't present.

Literal: %control, %control,.4

VPControlRef !PControlRef

A pitch control name. The scale is taken from the environ. Unlike a control signal, the empty string is a valid signal name and means the default pitch signal. The # val call is needed to make a pitch signal with a default.

Literal: #, #pitch, (# pitch (4c))

VPitch !Pitch

No literal, but is returned from val calls, notably scale calls.

VNotePitch !Pitch.Pitch

A parsed Pitch.Note. This is useful for things for which a textual Pitch.Note is too high level and a numerical Pitch.NoteNumber is too low level, like instrument ranges.

Literal: (pitch 4 0 1) -> 4c#.

VStr !Expr.Str

A string. There is an unquoted and a quoted form, parsed at p_unquoted_str and p_str.

Literal: func, 'hello', 'quinn''s hat'

VQuoted !Quoted

A quoted expression. Quoted calls are resolved by Derive.Sig when it typechecks arguments. This way you can set an argument default to an expression that will be evaluated every time the call occurs. Derive.Sig expects that the expression is a valid val call, which means no pipes.

Literal: "(a b c)

VControlFunction !ControlFunction 

An explicit not-given arg for functions so you can use positional args with defaults.

Literal: _


A token used as a separator when calls want to parse their argument lists via their own complicated means.

Literal: ;

VList ![Val]

List of values.

Literal: (list), (list 1 2), (list (x) (y))


Show Val # 


showsPrec :: Int -> Val -> ShowS #

show :: Val -> String #

showList :: [Val] -> ShowS #

DeepSeq.NFData Val # 


rnf :: Val -> () #

Pretty.Pretty Val # 
ShowVal.ShowVal Val #

This instance is actually invalid due to showing VPitch, which has no literal, and for Val, showing PControlRef, which amounts to the same thing. I use this to treat any Val as a Str to re-evaluate it. Being invalid means that a VPitch or VPControlRef with a default will cause a parse failure, but I'll have to see if this becomes a problem in practice.


show_val :: Val -> Text Source #

ToVal Val # 


to_val :: Val -> Val Source #

Typecheck Val # 

vals_equal :: Val -> Val -> Maybe Bool Source #

Return Nothing if the Vals can't be compared, and whether or not they're equal otherwise.

lists_equal :: (a -> a -> Maybe Bool) -> [a] -> [a] -> Maybe Bool Source #

newtype Quoted Source #


Quoted Expr 


Show Quoted # 
Pretty.Pretty Quoted # 
ShowVal.ShowVal Quoted #

Unlike Exprs in general, a Quoted Expr should be representable with show_val. This is because a Quoted has only been parsed, not evaluated, so it shouldn't have anything unshowable, like pitches.


show_val :: Quoted -> Text Source #

ToVal Quoted # 


to_val :: Quoted -> Val Source #

Typecheck Quoted #

Anything except a pitch can be coerced to a quoted, using ShowVal. This means you can write a lot of things without quotes.

Pitches have to be quoted because they explicitly have an invalid ShowVal.

show_call_val :: Val -> Text Source #

Show a str intended for call position. Call position is special in that it can contain any character except space and equals without quoting.

val utils

num :: Double -> Val Source #

Make an untyped VNum.


data Ref control val Source #


ControlSignal val

A signal literal.

DefaultedControl control val

If the control isn't present, use the given default.

LiteralControl control

Throw an exception if the control isn't present.


Pretty.Pretty PControlRef # 
Pretty.Pretty ControlRef # 
ShowVal.ShowVal 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 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.

ShowVal.ShowVal 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.

ToVal ControlRef # 
ToVal PControlRef # 
ToVal ControlRef # 
Typecheck PControlRef # 
Typecheck ControlRef #

Use a TypedFunction or Function instead of this.

(Eq control, Eq val) => Eq (Ref control val) # 


(==) :: Ref control val -> Ref control val -> Bool #

(/=) :: Ref control val -> Ref control val -> Bool #

(Read control, Read val) => Read (Ref control val) # 


readsPrec :: Int -> ReadS (Ref control val) #

readList :: ReadS [Ref control val] #

readPrec :: ReadPrec (Ref control val) #

readListPrec :: ReadPrec [Ref control val] #

(Show control, Show val) => Show (Ref control val) # 


showsPrec :: Int -> Ref control val -> ShowS #

show :: Ref control val -> String #

showList :: [Ref control val] -> ShowS #

(Serialize.Serialize val, Serialize.Serialize control) => Serialize.Serialize (Ref control val) # 


put :: Putter (Ref control val) Source #

get :: Serialize.Get (Ref control val) Source #

show_control :: ShowVal.ShowVal control => (sig -> Text) -> Ref control sig -> Text Source #

real_control :: ScoreTypes.Control -> RealTime.RealTime -> ControlRef Source #

Defaulted control from a RealTime.


type PitchCall = Call Source #

This is just a Call, but it's expected to return a VPitch.

call utils

map_str :: (Expr.Str -> Expr.Str) -> Call -> Call Source #

Transform the Symbols in a Call.




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].


ControlFunction !Text !(ScoreTypes.Control -> Dynamic -> RealTime.RealTime -> ScoreTypes.TypedVal)

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.

modify_control_function :: ((RealTime.RealTime -> ScoreTypes.TypedVal) -> RealTime.RealTime -> ScoreTypes.TypedVal) -> ControlFunction -> ControlFunction Source #

Modify the underlying function, presumably to compose something onto the input or output.

data Dynamic Source #

A stripped down Derive.Deriver.Monad.Dynamic for ControlFunctions to use. The duplication is unfortunate, see ControlFunction.