vivid-0.2.0.5: Sound synthesis with SuperCollider

Safe HaskellNone
LanguageHaskell98
Extensions
  • MonoLocalBinds
  • BangPatterns
  • TypeFamilies
  • OverloadedStrings
  • ViewPatterns
  • DataKinds
  • KindSignatures
  • ExplicitNamespaces
  • LambdaCase

Vivid.SynthDef

Contents

Description

Synth Definitions in SuperCollider are how you define the way synths should sound -- you describe parameters and a graph of sound generators, add them to the server with defineSD, and then create instances of the Synth Definition (called "synths"), which each play separately. You can set parameters of the synth at any time while they're playing

Usually, you shouldn't be making SynthDefs explicitly -- there's a state monad SDBody which lets you construct synthdefs like so:

  test :: SynthDef
  test = sd (0 ::I "note") $ do
     s <- 0.1 ~* sinOsc (freq_ $ midiCPS (V::V "note"))
     out 0 [s, s]
  

You then optionally explicitly send the synth definition to the SC server with

>>> defineSD test

You then create a synth from the synthdef like:

>>> s <- synth test (45 ::I "note")

This returns a NodeId which is a reference to the synth, which you can use to e.g. change the params of the running synth with e.g.

>>> set s (38 ::I "note")

Then you can free it (stop its playing) with

>>> free s

(If you want interop with SClang, use "sdNamed" and "synthNamed")

Synopsis

Synth actions

Synth Definition Construction

data SynthDef args Source

Internal representation of Synth Definitions. Usually, use sd instead of making these by hand.

This representation (especially _sdUGens) might change in the future.

Constructors

SynthDef 

Instances

Show (SynthDef args) Source 
(~) [Symbol] a args => ToSig (SDBody' a Signal) args Source 

data UGen Source

Representation of Unit Generators. You usually won't be creating these by hand, but instead using things from the library in UGens

addMonoUGen :: UGen -> SDBody' args Signal Source

Add a unit generator with one output

addPolyUGen :: UGen -> SDBody' args [Signal] Source

Polyphonic -- returns a list of Signals. In the future this might be a tuple instead of a list

class ToSig s args where Source

Don't define other instances of this! (Unless you know what you're doing) Instance resolution could get screwed up.

Methods

toSig :: s -> SDBody' args Signal Source

Instances

(Num n, Real n) => ToSig n args Source

For Constant (Float) values

ToSig Signal args Source 
ToSig BufferId args Source 
(KnownSymbol a, Subset ((:) Symbol a ([] Symbol)) args) => ToSig (Variable a) args Source 
(~) [Symbol] a args => ToSig (SDBody' a Signal) args Source 

sd :: VarList argList => argList -> SDBody' (InnerVars argList) [Signal] -> SynthDef (InnerVars argList) Source

Define a Synth Definition

sdNamed :: VarList argList => String -> argList -> SDBody' (InnerVars argList) [Signal] -> SynthDef (InnerVars argList) Source

Define a Synth Definition and give it a name you can refer to from e.g. sclang

(?) :: SDBody' args Signal -> CalculationRate -> SDBody' args Signal Source

Set the calculation rate of a UGen

e.g.

play $ do
   s0 <- 1 ~+ (lfSaw (freq_ 1) ? KR)
   s1 <- 0.1 ~* lfSaw (freq_ $ 220 ~* s0)
   out 0 [s1, s1]

Mnemonic: "?" is like thinking

In the future, the representation of calculation rates may change

data DoneAction Source

Action to take with a UGen when it's finished

This representation will change in the future

execState

Arguments

:: State s a

state-passing computation to execute

-> s

initial value

-> s

final state

Evaluate a state computation with the given initial state and return the final state, discarding the final value.

Built-in Unit Generator Operations

data UnaryOp Source

Unary signal operations. Many of these have functions so you don't need to use this internal representation (e.g. Neg has neg, etc).

This type might not be exposed in the future.

Constructors

Neg 
Not 
IsNil 
NotNil 
BitNot

There's a bug in some SC versions where .bitNot isn't implemented correctly. Vivid backfills it with a fix, so you can use BitNot with any SC version

Abs 
AsFloat 
AsInt 
Ciel 
Floor 
Frac 
Sign 
Squared 
Cubed 
Sqrt 
Exp 
Recip 
MIDICPS 
CPSMIDI 
MIDIRatio 
RatioMIDI 
DbAmp 
AmpDb 
OctCPS 
CPSOct 
Log 
Log2 
Log10 
Sin 
Cos 
Tan 
ArcSin 
ArcCos 
ArcTan 
SinH 
CosH 
TanH 
Rand 
Rand2 
LinRand 
BiLinRand 
Sum3Rand 
Distort 
SoftClip 
Coin 
DigitValue 
Silence 
Thru 
RectWindow 
HanWindow 
WelchWindow 
TriWindow 
Ramp 
SCurve 
NumUnarySelectors 

data BinaryOp Source

Binary signal operations. For the simple ones (like Add, Mul, etc.), there are functions (like ~+, ~*, etc.) that wrap them up so you don't have to make a ugen for them yourself.

In the future these may not be exported -- we'll just have functions for all of them.

Constructors

Add 
Sub 
Mul 
IDiv

Integer division

FDiv

Float division

Mod 
Eq 
Ne 
Lt 
Gt 
Le 
Ge 
Min 
Max 
BitAnd 
BitOr 
BitXor 
Lcm 
Gcd 
Round 
RoundUp 
Trunc 
Atan2 
Hypot 
Hypotx 
Pow 
ShiftLeft 
ShiftRight 
UnsignedShift 
Fill 
Ring1

a * (b + 1) == a * b + a

Ring2

a * b + a + b

Ring3

a * a * b

Ring4

a * a * b - a * b * b

DifSqr

a * a - b * b

SumSqr

a * a + b * b

SqrSum

(a + b) ^ 2

SqrDif

(a - b) ^ 2

AbsDif

abs(a - b)

Thresh 
AMClip 
ScaleNeg 
Clip2 
Excess 
Fold2 
Wrap2 
FirstArg 
RandRange 
ExpRandRange 
NumBinarySelectors 

makeSynthDef :: VarList argList => SDName -> argList -> SDBody' (InnerVars argList) [Signal] -> SynthDef (InnerVars argList) Source

shrinkSDArgs :: Subset new old => SynthDef old -> SynthDef new Source

Like shrinkNodeArgs but for SynthDefs