Safe Haskell | None |
---|---|
Language | Haskell2010 |
We can convert notes to sound signals with instruments. An instrument is a function:
(Arg a, Sigs b) => a -> SE b
It takes a tuple of primitive Csound values (number, string or array) and converts
it to the tuple of signals and it makes some side effects along the way so
the output is wrapped in the SE
-monad.
There are only three ways of making a sound with an instrument:
- Suplpy an instrument with notes (
Mix
-section). - Trigger an instrument with event stream (
Evt
-section). - By using midi-instruments (see
Csound.Control.Midi
).
Sometimes we don't want to produce any sound. Our instrument is just a procedure that makes something useful without being noisy about it. It's type is:
(Arg a) => a -> SE ()
To invoke the procedures there are functions with trailing underscore.
For example we have the function trig
to convert event stream to sound:
trig :: (Arg a, Sigs b) => (a -> SE b) -> Evts (D, D, a) -> b
and we have a trig
with underscore to convert the event stream to
the sequence of the procedure invkations:
trig_ :: (Arg a) => (a -> SE ()) -> Evts (D, D, a) -> SE ()
To invoke instruments from another instrumetnts we use artificial closures made with functions with trailing xxxBy. For example:
trigBy :: (Arg a, Arg c, Sigs b) => (a -> SE b) -> (c -> Evts (D, D, a)) -> (c -> b)
Notice that the event stream depends on the argument of the type c. Here goes all the parameters that we want to pass from the outer instrument. Unfortunately we can not just create the closure, because our values are not the real values. It's a text of the programm (a tiny snippet of it) to be executed. For a time being I don't know how to make it better. So we need to pass the values explicitly.
For example, if we want to make an arpeggiator:
pureTone :: D -> SE Sig pureTone cps = return $ mul env $ osc $ sig cps where env = linseg [0, 0.01, 1, 0.25, 0] majArpeggio :: D -> SE Sig majArpeggio = return . schedBy pureTone evts where evts cps = withDur 0.5 $ fmap (* cps) $ cycleE [1, 5/3, 3/2, 2] $ metroE 5 main = dac $ mul 0.5 $ midi $ onMsg majArpeggio
We should use schedBy
to pass the frequency as a parameter to the event stream.
Synopsis
- type Sco a = Track Sig a
- data Mix a
- sco :: (Arg a, Sigs b) => (a -> SE b) -> Sco a -> Sco (Mix b)
- mix :: Sigs a => Sco (Mix a) -> a
- eff :: (Sigs a, Sigs b) => (a -> SE b) -> Sco (Mix a) -> Sco (Mix b)
- monoSco :: Sigs a => (MonoArg -> SE a) -> Sco (D, D) -> Sco (Mix a)
- mixLoop :: Sigs a => Sco (Mix a) -> a
- sco_ :: Arg a => (a -> SE ()) -> Sco a -> Sco (Mix Unit)
- mix_ :: Sco (Mix Unit) -> SE ()
- mixLoop_ :: Sco (Mix Unit) -> SE ()
- mixBy :: (Arg a, Sigs b) => (a -> Sco (Mix b)) -> a -> b
- infiniteDur :: Num a => a
- (<>) :: Semigroup a => a -> a -> a
- class Semigroup a => Monoid a where
- newtype First a = First {}
- newtype Last a = Last {}
- newtype Ap (f :: k -> Type) (a :: k) :: forall k. (k -> Type) -> k -> Type = Ap {
- getAp :: f a
- newtype Dual a = Dual {
- getDual :: a
- newtype Endo a = Endo {
- appEndo :: a -> a
- newtype All = All {}
- newtype Any = Any {}
- newtype Sum a = Sum {
- getSum :: a
- newtype Product a = Product {
- getProduct :: a
- newtype Alt (f :: k -> Type) (a :: k) :: forall k. (k -> Type) -> k -> Type = Alt {
- getAlt :: f a
- linfunRel :: (Ord t, Fractional t) => t -> [t] -> t -> t
- linfun :: (Ord t, Fractional t) => [t] -> t -> t
- sortEvents :: Ord t => [Event t a] -> [Event t a]
- alignByZero :: Real t => [Event t a] -> [Event t a]
- sustainT :: (Ord t, Num t) => t -> Track t a -> Track t a
- sustain :: Num t => t -> Track t a -> Track t a
- tmapRel :: RealFrac t => (Event t a -> b) -> Track t a -> Track t b
- tmap :: Real t => (Event t a -> b) -> Track t a -> Track t b
- filterEvents :: Real t => (Event t a -> Bool) -> Track t a -> Track t a
- traverseEvents :: (Num t1, Applicative f) => (t1 -> f t2) -> (Event t1 a -> f (Event t2 b)) -> Track t1 a -> f (Track t2 b)
- mapEvents :: Num t => (Event t a -> Event t b) -> Track t a -> Track t b
- within :: Real t => t -> t -> Event t a -> Bool
- eventEnd :: Num t => Event t a -> t
- render :: Num t => Track t a -> [Event t a]
- singleEvent :: Num t => t -> t -> a -> Track t a
- fromEvent :: Num t => Event t a -> Track t a
- temp :: Num t => a -> Track t a
- dropT :: Real t => t -> Track t a -> Track t a
- takeT :: Real t => t -> Track t a -> Track t a
- slice :: Real t => t -> t -> Track t a -> Track t a
- reflect :: (Num t, IfB t, OrdB t) => Track t a -> Track t a
- harTMap :: (Real t, IfB t, OrdB t) => (a -> Track t b) -> [a] -> Track t b
- harTemp :: (Num t, IfB t, OrdB t) => [a] -> Track t a
- melTemp :: (Num t, IfB t, OrdB t) => [a] -> Track t a
- harT :: (Real t, IfB t, OrdB t) => [Track t a] -> Track t a
- (=:/) :: (Real t, IfB t, OrdB t) => Track t a -> Track t a -> Track t a
- nil :: Monoid a => a
- data Track t a
- data Event t a = Event {
- eventStart :: t
- eventDur :: t
- eventContent :: a
- harMap :: Harmony b => (a -> b) -> [a] -> b
- melMap :: Melody b => (a -> b) -> [a] -> b
- (*|) :: Stretch a => DurOf a -> a -> a
- (+|) :: Delay a => DurOf a -> a -> a
- loopBy :: Melody a => Int -> a -> a
- class Duration a where
- type family DurOf a :: Type
- class Melody a where
- class Harmony a where
- class (Melody a, Harmony a) => Compose a
- class Delay a where
- class Stretch a where
- class Rest a where
- class Limit a where
- class Loop a where
- loop :: a -> a
- sched :: (Arg a, Sigs b) => (a -> SE b) -> Evt (Sco a) -> b
- retrig :: (Arg a, Sigs b) => (a -> SE b) -> Evt a -> b
- schedHarp :: (Arg a, Sigs b) => D -> (a -> SE b) -> Evt [a] -> b
- schedUntil :: (Arg a, Sigs b) => (a -> SE b) -> Evt a -> Evt c -> b
- schedToggle :: Sigs b => SE b -> Evt D -> b
- sched_ :: Arg a => (a -> SE ()) -> Evt (Sco a) -> SE ()
- schedUntil_ :: Arg a => (a -> SE ()) -> Evt a -> Evt c -> SE ()
- schedBy :: (Arg a, Sigs b, Arg c) => (a -> SE b) -> (c -> Evt (Sco a)) -> c -> b
- schedHarpBy :: (Arg a, Sigs b, Arg c) => D -> (a -> SE b) -> (c -> Evt [a]) -> c -> b
- withDur :: Sig -> Evt a -> Evt (Sco a)
- monoSched :: Evt (Sco (D, D)) -> SE MonoArg
- trigByName :: (Arg a, Sigs b) => String -> (a -> SE b) -> SE b
- trigByName_ :: Arg a => String -> (a -> SE ()) -> SE ()
- trigByNameMidi :: (Arg a, Sigs b) => String -> ((D, D, a) -> SE b) -> SE b
- trigByNameMidi_ :: Arg a => String -> ((D, D, a) -> SE ()) -> SE ()
- turnoffByName :: String -> Sig -> Sig -> SE ()
- alwaysOn :: SE () -> SE ()
- playWhen :: forall a b. Sigs a => BoolSig -> (b -> SE a) -> b -> SE a
- class Sigs (SigOuts a) => Outs a where
- onArg :: Outs b => (a -> b) -> a -> SE (SigOuts b)
- class AmpInstr a where
- type AmpInstrOut a :: *
- onAmp :: a -> D -> SE (AmpInstrOut a)
- class CpsInstr a where
- type CpsInstrOut a :: *
- onCps :: a -> (D, D) -> SE (CpsInstrOut a)
- data InstrRef a
- newInstr :: Arg a => (a -> SE ()) -> SE (InstrRef a)
- scheduleEvent :: Arg a => InstrRef a -> D -> D -> a -> SE ()
- turnoff2 :: InstrRef a -> Sig -> Sig -> SE ()
- negateInstrRef :: InstrRef a -> InstrRef a
- addFracInstrRef :: D -> D -> InstrRef a -> InstrRef a
- newOutInstr :: (Arg a, Sigs b) => (a -> SE b) -> SE (InstrRef a, b)
- noteOn :: Arg a => D -> D -> InstrRef a -> a -> SE ()
- noteOff :: (Default a, Arg a) => D -> D -> InstrRef a -> SE ()
Mix
We can invoke instrument with specified notes. Eqch note happens at some time and lasts for some time. It contains the argument for the instrument.
We can invoke the instrument on the sequence of notes (sco
), process
the sequence of notes with an effect (eff
) and convert everything in
the plain sound signals (to send it to speakers or write to file or
use it in some another instrument).
The sequence of notes is represented with type class CsdSco
. Wich
has a very simple methods. So you can use your own favorite library
to describe the list of notes. If your type supports the scaling in
the time domain (stretching the timeline) you can do it in the Mix-version
(after the invokation of the instrument). All notes are rescaled all the
way down the Score-structure.
Special type that represents a scores of sound signals. If an instrument is triggered with the scores the result is wrapped in the value of this type.
sco :: (Arg a, Sigs b) => (a -> SE b) -> Sco a -> Sco (Mix b) #
Plays a bunch of notes with the given instrument.
res = sco instrument scores
mix :: Sigs a => Sco (Mix a) -> a #
Renders a scores to the sound signals. we can use it inside the other instruments.
eff :: (Sigs a, Sigs b) => (a -> SE b) -> Sco (Mix a) -> Sco (Mix b) #
Applies an effect to the sound. Effect is applied to the sound on the give track.
res = eff effect sco
effect
- a function that takes a tuple of signals and produces a tuple of signals.sco
- something that is constructed withsco
oreff
.
With the function eff
you can apply a reverb or adjust the
level of the signal. It functions like a mixing board but unlike mixing
board it produces the value that you can arrange with functions from your
favorite Score-generation library. You can delay it or mix with some other track and
apply some another effect on top of it!
monoSco :: Sigs a => (MonoArg -> SE a) -> Sco (D, D) -> Sco (Mix a) #
Plays a bunch of notes with the given monophonic instrument. See details on type MonoArg
.
The scores contain the pairs of amplitude (0 to 1) and frequency (in Hz).
res = monoSco instrument scores
sco_ :: Arg a => (a -> SE ()) -> Sco a -> Sco (Mix Unit) #
Invokes a procedure for the given bunch of events.
mix_ :: Sco (Mix Unit) -> SE () #
Converts a bunch of procedures scheduled with scores to a single procedure.
mixBy :: (Arg a, Sigs b) => (a -> Sco (Mix b)) -> a -> b #
Imitates a closure for a bunch of notes to be played within another instrument.
infiniteDur :: Num a => a #
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
x
<>
mempty
= xmempty
<>
x = xx
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)mconcat
=foldr
'(<>)'mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= '(<>)'
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
Monoid Ordering | Since: base-2.1 |
Monoid () | Since: base-2.1 |
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid IntSet | |
Monoid Flags | |
Monoid AudioFileOutput | |
Defined in Csound.Dynamic.Types.Flags mappend :: AudioFileOutput -> AudioFileOutput -> AudioFileOutput # mconcat :: [AudioFileOutput] -> AudioFileOutput # | |
Monoid IdTags | |
Monoid MidiIO | |
Monoid MidiRT | |
Monoid Displays | |
Monoid Config | |
Monoid Props | |
Monoid Sig | |
Monoid D | |
Monoid Unit | |
Monoid Options | |
Monoid Doc | |
Monoid [a] | Since: base-2.1 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
(Ord a, Bounded a) => Monoid (Min a) | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
Semigroup a => Monoid (Option a) | Since: base-4.9.0.0 |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Monoid (First a) | Since: base-2.1 |
Monoid (Last a) | Since: base-2.1 |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Monoid a => Monoid (Down a) | Since: base-4.11.0.0 |
Num a => Monoid (Colour a) | |
Num a => Monoid (AlphaColour a) | |
Defined in Data.Colour.Internal mempty :: AlphaColour a # mappend :: AlphaColour a -> AlphaColour a -> AlphaColour a # mconcat :: [AlphaColour a] -> AlphaColour a # | |
Monoid (IntMap a) | |
Monoid (Seq a) | |
Ord a => Monoid (Set a) | |
Monoid (Evt a) | |
Monoid (DList a) | |
Monoid (Doc a) | |
Monoid (MergeSet a) | |
Monoid b => Monoid (a -> b) | Since: base-2.1 |
Monoid (U1 p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Ord k => Monoid (Map k v) | |
Monoid (AbsScene ctx a) | |
(Num t, IfB t, OrdB t) => Monoid (Track t a) | |
Monoid (TList t a) | |
Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1 |
Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1 |
Maybe monoid returning the leftmost non-Nothing value.
is isomorphic to First
a
, but precedes it
historically.Alt
Maybe
a
>>>
getFirst (First (Just "hello") <> First Nothing <> First (Just "world"))
Just "hello"
Use of this type is discouraged. Note the following equivalence:
Data.Monoid.First x === Maybe (Data.Semigroup.First x)
In addition to being equivalent in the structural sense, the two
also have Monoid
instances that behave the same. This type will
be marked deprecated in GHC 8.8, and removed in GHC 8.10.
Users are advised to use the variant from Data.Semigroup and wrap
it in Maybe
.
Instances
Monad First | Since: base-4.8.0.0 |
Functor First | Since: base-4.8.0.0 |
Applicative First | Since: base-4.8.0.0 |
Foldable First | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => First m -> m # foldMap :: Monoid m => (a -> m) -> First a -> m # foldr :: (a -> b -> b) -> b -> First a -> b # foldr' :: (a -> b -> b) -> b -> First a -> b # foldl :: (b -> a -> b) -> b -> First a -> b # foldl' :: (b -> a -> b) -> b -> First a -> b # foldr1 :: (a -> a -> a) -> First a -> a # foldl1 :: (a -> a -> a) -> First a -> a # elem :: Eq a => a -> First a -> Bool # maximum :: Ord a => First a -> a # minimum :: Ord a => First a -> a # | |
Traversable First | Since: base-4.8.0.0 |
Eq a => Eq (First a) | Since: base-2.1 |
Ord a => Ord (First a) | Since: base-2.1 |
Read a => Read (First a) | Since: base-2.1 |
Show a => Show (First a) | Since: base-2.1 |
Generic (First a) | |
Semigroup (First a) | Since: base-4.9.0.0 |
Monoid (First a) | Since: base-2.1 |
Default (First a) | |
Defined in Data.Default.Class | |
Generic1 First | |
type Rep (First a) | Since: base-4.7.0.0 |
Defined in Data.Monoid | |
type Rep1 First | Since: base-4.7.0.0 |
Defined in Data.Monoid |
Maybe monoid returning the rightmost non-Nothing value.
is isomorphic to Last
a
, and thus to
Dual
(First
a)Dual
(Alt
Maybe
a)
>>>
getLast (Last (Just "hello") <> Last Nothing <> Last (Just "world"))
Just "world"
Use of this type is discouraged. Note the following equivalence:
Data.Monoid.Last x === Maybe (Data.Semigroup.Last x)
In addition to being equivalent in the structural sense, the two
also have Monoid
instances that behave the same. This type will
be marked deprecated in GHC 8.8, and removed in GHC 8.10.
Users are advised to use the variant from Data.Semigroup and wrap
it in Maybe
.
Instances
Monad Last | Since: base-4.8.0.0 |
Functor Last | Since: base-4.8.0.0 |
Applicative Last | Since: base-4.8.0.0 |
Foldable Last | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Last m -> m # foldMap :: Monoid m => (a -> m) -> Last a -> m # foldr :: (a -> b -> b) -> b -> Last a -> b # foldr' :: (a -> b -> b) -> b -> Last a -> b # foldl :: (b -> a -> b) -> b -> Last a -> b # foldl' :: (b -> a -> b) -> b -> Last a -> b # foldr1 :: (a -> a -> a) -> Last a -> a # foldl1 :: (a -> a -> a) -> Last a -> a # elem :: Eq a => a -> Last a -> Bool # maximum :: Ord a => Last a -> a # | |
Traversable Last | Since: base-4.8.0.0 |
Eq a => Eq (Last a) | Since: base-2.1 |
Ord a => Ord (Last a) | Since: base-2.1 |
Read a => Read (Last a) | Since: base-2.1 |
Show a => Show (Last a) | Since: base-2.1 |
Generic (Last a) | |
Semigroup (Last a) | Since: base-4.9.0.0 |
Monoid (Last a) | Since: base-2.1 |
Default (Last a) | |
Defined in Data.Default.Class | |
Generic1 Last | |
type Rep (Last a) | Since: base-4.7.0.0 |
Defined in Data.Monoid | |
type Rep1 Last | Since: base-4.7.0.0 |
Defined in Data.Monoid |
newtype Ap (f :: k -> Type) (a :: k) :: forall k. (k -> Type) -> k -> Type #
This data type witnesses the lifting of a Monoid
into an
Applicative
pointwise.
Since: base-4.12.0.0
Instances
Generic1 (Ap f :: k -> Type) | |
Monad f => Monad (Ap f) | Since: base-4.12.0.0 |
Functor f => Functor (Ap f) | Since: base-4.12.0.0 |
MonadFail f => MonadFail (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
Foldable f => Foldable (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Ap f m -> m # foldMap :: Monoid m => (a -> m) -> Ap f a -> m # foldr :: (a -> b -> b) -> b -> Ap f a -> b # foldr' :: (a -> b -> b) -> b -> Ap f a -> b # foldl :: (b -> a -> b) -> b -> Ap f a -> b # foldl' :: (b -> a -> b) -> b -> Ap f a -> b # foldr1 :: (a -> a -> a) -> Ap f a -> a # foldl1 :: (a -> a -> a) -> Ap f a -> a # elem :: Eq a => a -> Ap f a -> Bool # maximum :: Ord a => Ap f a -> a # | |
Traversable f => Traversable (Ap f) | Since: base-4.12.0.0 |
Alternative f => Alternative (Ap f) | Since: base-4.12.0.0 |
MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0 |
(Applicative f, Bounded a) => Bounded (Ap f a) | Since: base-4.12.0.0 |
Enum (f a) => Enum (Ap f a) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
Eq (f a) => Eq (Ap f a) | Since: base-4.12.0.0 |
(Applicative f, Num a) => Num (Ap f a) | Since: base-4.12.0.0 |
Ord (f a) => Ord (Ap f a) | Since: base-4.12.0.0 |
Read (f a) => Read (Ap f a) | Since: base-4.12.0.0 |
Show (f a) => Show (Ap f a) | Since: base-4.12.0.0 |
Generic (Ap f a) | |
(Applicative f, Semigroup a) => Semigroup (Ap f a) | Since: base-4.12.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
type Rep1 (Ap f :: k -> Type) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
type Rep (Ap f a) | Since: base-4.12.0.0 |
Defined in Data.Monoid |
The dual of a Monoid
, obtained by swapping the arguments of mappend
.
>>>
getDual (mappend (Dual "Hello") (Dual "World"))
"WorldHello"
Instances
Monad Dual | Since: base-4.8.0.0 |
Functor Dual | Since: base-4.8.0.0 |
Applicative Dual | Since: base-4.8.0.0 |
Foldable Dual | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Dual m -> m # foldMap :: Monoid m => (a -> m) -> Dual a -> m # foldr :: (a -> b -> b) -> b -> Dual a -> b # foldr' :: (a -> b -> b) -> b -> Dual a -> b # foldl :: (b -> a -> b) -> b -> Dual a -> b # foldl' :: (b -> a -> b) -> b -> Dual a -> b # foldr1 :: (a -> a -> a) -> Dual a -> a # foldl1 :: (a -> a -> a) -> Dual a -> a # elem :: Eq a => a -> Dual a -> Bool # maximum :: Ord a => Dual a -> a # | |
Traversable Dual | Since: base-4.8.0.0 |
Bounded a => Bounded (Dual a) | Since: base-2.1 |
Eq a => Eq (Dual a) | Since: base-2.1 |
Ord a => Ord (Dual a) | Since: base-2.1 |
Read a => Read (Dual a) | Since: base-2.1 |
Show a => Show (Dual a) | Since: base-2.1 |
Generic (Dual a) | |
Semigroup a => Semigroup (Dual a) | Since: base-4.9.0.0 |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Default a => Default (Dual a) | |
Defined in Data.Default.Class | |
Generic1 Dual | |
type Rep (Dual a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Dual | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
The monoid of endomorphisms under composition.
>>>
let computation = Endo ("Hello, " ++) <> Endo (++ "!")
>>>
appEndo computation "Haskell"
"Hello, Haskell!"
Boolean monoid under conjunction (&&
).
>>>
getAll (All True <> mempty <> All False)
False
>>>
getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
False
Instances
Bounded All | Since: base-2.1 |
Eq All | Since: base-2.1 |
Ord All | Since: base-2.1 |
Read All | Since: base-2.1 |
Show All | Since: base-2.1 |
Generic All | |
Semigroup All | Since: base-4.9.0.0 |
Monoid All | Since: base-2.1 |
Default All | |
Defined in Data.Default.Class | |
type Rep All | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
Boolean monoid under disjunction (||
).
>>>
getAny (Any True <> mempty <> Any False)
True
>>>
getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
True
Instances
Bounded Any | Since: base-2.1 |
Eq Any | Since: base-2.1 |
Ord Any | Since: base-2.1 |
Read Any | Since: base-2.1 |
Show Any | Since: base-2.1 |
Generic Any | |
Semigroup Any | Since: base-4.9.0.0 |
Monoid Any | Since: base-2.1 |
Default Any | |
Defined in Data.Default.Class | |
type Rep Any | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
Monoid under addition.
>>>
getSum (Sum 1 <> Sum 2 <> mempty)
3
Instances
Monad Sum | Since: base-4.8.0.0 |
Functor Sum | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Foldable Sum | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Sum m -> m # foldMap :: Monoid m => (a -> m) -> Sum a -> m # foldr :: (a -> b -> b) -> b -> Sum a -> b # foldr' :: (a -> b -> b) -> b -> Sum a -> b # foldl :: (b -> a -> b) -> b -> Sum a -> b # foldl' :: (b -> a -> b) -> b -> Sum a -> b # foldr1 :: (a -> a -> a) -> Sum a -> a # foldl1 :: (a -> a -> a) -> Sum a -> a # elem :: Eq a => a -> Sum a -> Bool # maximum :: Ord a => Sum a -> a # | |
Traversable Sum | Since: base-4.8.0.0 |
Bounded a => Bounded (Sum a) | Since: base-2.1 |
Eq a => Eq (Sum a) | Since: base-2.1 |
Num a => Num (Sum a) | Since: base-4.7.0.0 |
Ord a => Ord (Sum a) | Since: base-2.1 |
Read a => Read (Sum a) | Since: base-2.1 |
Show a => Show (Sum a) | Since: base-2.1 |
Generic (Sum a) | |
Num a => Semigroup (Sum a) | Since: base-4.9.0.0 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Default (Sum a) | |
Defined in Data.Default.Class | |
Generic1 Sum | |
type Rep (Sum a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Sum | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
Monoid under multiplication.
>>>
getProduct (Product 3 <> Product 4 <> mempty)
12
Product | |
|
Instances
Monad Product | Since: base-4.8.0.0 |
Functor Product | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Foldable Product | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Product m -> m # foldMap :: Monoid m => (a -> m) -> Product a -> m # foldr :: (a -> b -> b) -> b -> Product a -> b # foldr' :: (a -> b -> b) -> b -> Product a -> b # foldl :: (b -> a -> b) -> b -> Product a -> b # foldl' :: (b -> a -> b) -> b -> Product a -> b # foldr1 :: (a -> a -> a) -> Product a -> a # foldl1 :: (a -> a -> a) -> Product a -> a # elem :: Eq a => a -> Product a -> Bool # maximum :: Ord a => Product a -> a # minimum :: Ord a => Product a -> a # | |
Traversable Product | Since: base-4.8.0.0 |
Bounded a => Bounded (Product a) | Since: base-2.1 |
Eq a => Eq (Product a) | Since: base-2.1 |
Num a => Num (Product a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
Ord a => Ord (Product a) | Since: base-2.1 |
Defined in Data.Semigroup.Internal | |
Read a => Read (Product a) | Since: base-2.1 |
Show a => Show (Product a) | Since: base-2.1 |
Generic (Product a) | |
Num a => Semigroup (Product a) | Since: base-4.9.0.0 |
Num a => Monoid (Product a) | Since: base-2.1 |
Num a => Default (Product a) | |
Defined in Data.Default.Class | |
Generic1 Product | |
type Rep (Product a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Product | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
newtype Alt (f :: k -> Type) (a :: k) :: forall k. (k -> Type) -> k -> Type #
Monoid under <|>
.
Since: base-4.8.0.0
Instances
Generic1 (Alt f :: k -> Type) | |
Monad f => Monad (Alt f) | Since: base-4.8.0.0 |
Functor f => Functor (Alt f) | Since: base-4.8.0.0 |
Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
Foldable f => Foldable (Alt f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Alt f m -> m # foldMap :: Monoid m => (a -> m) -> Alt f a -> m # foldr :: (a -> b -> b) -> b -> Alt f a -> b # foldr' :: (a -> b -> b) -> b -> Alt f a -> b # foldl :: (b -> a -> b) -> b -> Alt f a -> b # foldl' :: (b -> a -> b) -> b -> Alt f a -> b # foldr1 :: (a -> a -> a) -> Alt f a -> a # foldl1 :: (a -> a -> a) -> Alt f a -> a # elem :: Eq a => a -> Alt f a -> Bool # maximum :: Ord a => Alt f a -> a # minimum :: Ord a => Alt f a -> a # | |
Traversable f => Traversable (Alt f) | Since: base-4.12.0.0 |
Alternative f => Alternative (Alt f) | Since: base-4.8.0.0 |
MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0 |
Enum (f a) => Enum (Alt f a) | Since: base-4.8.0.0 |
Eq (f a) => Eq (Alt f a) | Since: base-4.8.0.0 |
Num (f a) => Num (Alt f a) | Since: base-4.8.0.0 |
Ord (f a) => Ord (Alt f a) | Since: base-4.8.0.0 |
Read (f a) => Read (Alt f a) | Since: base-4.8.0.0 |
Show (f a) => Show (Alt f a) | Since: base-4.8.0.0 |
Generic (Alt f a) | |
Alternative f => Semigroup (Alt f a) | Since: base-4.9.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
type Rep1 (Alt f :: k -> Type) | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep (Alt f a) | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal |
linfunRel :: (Ord t, Fractional t) => t -> [t] -> t -> t #
With linfunRel
you can make linear interpolation
function that has equal distance between points.
First argument gives total length of the interpolation function
and second argument gives list of values. So call
linfunRel dur [a1, a2, a3, ..., aN]
is equivalent to:
linfun [a1, dur/N, a2, dur/N, a3, ..., dur/N, aN]
linfun :: (Ord t, Fractional t) => [t] -> t -> t #
Linear interpolation. Can be useful with mapEvents
for
envelope changes.
linfun [a, da, b, db, c, ... ]
a, b, c ...
- values
da, db, ...
- duration of segments
sortEvents :: Ord t => [Event t a] -> [Event t a] #
Sorts all events by start time.
alignByZero :: Real t => [Event t a] -> [Event t a] #
Shifts all events so that minimal start time equals to zero if first event has negative start time.
sustainT :: (Ord t, Num t) => t -> Track t a -> Track t a #
Prolongated events can not exceed total track duration. All event are sustained but those that are close to end of the track are sliced. It resembles sustain on piano, when track ends you release the pedal.
sustain :: Num t => t -> Track t a -> Track t a #
After this transformation events last longer by some constant amount of time.
tmapRel :: RealFrac t => (Event t a -> b) -> Track t a -> Track t b #
Relative tmap. Time values are normalized by argument's duration.
traverseEvents :: (Num t1, Applicative f) => (t1 -> f t2) -> (Event t1 a -> f (Event t2 b)) -> Track t1 a -> f (Track t2 b) #
mapEvents :: Num t => (Event t a -> Event t b) -> Track t a -> Track t b #
General mapping. Maps not only values but events.
within :: Real t => t -> t -> Event t a -> Bool #
Tests if given Event
happens between two time stamps.
singleEvent :: Num t => t -> t -> a -> Track t a #
Constructs a track that contains a single event.
singleEvent start duration content
temp :: Num t => a -> Track t a #
temp
constructs just an event.
Value of type a lasts for one time unit and starts at zero.
harTMap :: (Real t, IfB t, OrdB t) => (a -> Track t b) -> [a] -> Track t b #
Transforms a sequence and then applies a harT.
harTemp :: (Num t, IfB t, OrdB t) => [a] -> Track t a #
A chord of events. Each of them lasts for one second.
melTemp :: (Num t, IfB t, OrdB t) => [a] -> Track t a #
Analog of replicate
function for tracks. Replicated
tracks are played sequentially.
A melody of events. Each of them lasts for one second.
harT :: (Real t, IfB t, OrdB t) => [Track t a] -> Track t a #
Turncating parallel composition on list of tracks.
(=:/) :: (Real t, IfB t, OrdB t) => Track t a -> Track t a -> Track t a #
Turncating parallel composition. Total duration equals to minimum of the two tracks. All events that goes beyond the limit are dropped.
Track
is a set of Event
s. There is total duration
of the track, but Events can go beyond the scope of total duration
(as a result of mapEvents
function). Total duration is used in sequent
composition of tracks.
Instances
Functor (Track t) | |
Foldable (Track t) | |
Defined in Temporal.Media fold :: Monoid m => Track t m -> m # foldMap :: Monoid m => (a -> m) -> Track t a -> m # foldr :: (a -> b -> b) -> b -> Track t a -> b # foldr' :: (a -> b -> b) -> b -> Track t a -> b # foldl :: (b -> a -> b) -> b -> Track t a -> b # foldl' :: (b -> a -> b) -> b -> Track t a -> b # foldr1 :: (a -> a -> a) -> Track t a -> a # foldl1 :: (a -> a -> a) -> Track t a -> a # elem :: Eq a => a -> Track t a -> Bool # maximum :: Ord a => Track t a -> a # minimum :: Ord a => Track t a -> a # | |
Traversable (Track t) | |
(Eq t, Eq a) => Eq (Track t a) | |
(Show t, Show a) => Show (Track t a) | |
(Num t, IfB t, OrdB t) => Semigroup (Track t a) | |
(Num t, IfB t, OrdB t) => Monoid (Track t a) | |
Duration (Track t a) | |
(Num t, IfB t, OrdB t) => Melody (Track t a) | |
(Num t, IfB t, OrdB t) => Harmony (Track t a) | |
(Num t, IfB t, OrdB t) => Compose (Track t a) | |
Defined in Temporal.Media | |
Num t => Delay (Track t a) | Delays all events by given duration. |
Num t => Stretch (Track t a) | Stretches track in time domain. |
(Num t, IfB t, OrdB t) => Rest (Track t a) | Empty track that lasts for some time. |
type DurOf (Track t a) | |
Defined in Temporal.Media |
Constant time events. Value a
starts at some time
and lasts for some time.
Event | |
|
Calculates duration.
Duration for the given type.
Sequent composition for a list of values (melody).
Sequent composition. Play first track then second.
Parallel composition for a list of values (harmony).
Parallel composition. Play two tracks simultaneously.
Evt
schedHarp :: (Arg a, Sigs b) => D -> (a -> SE b) -> Evt [a] -> b #
An instrument is triggered with event stream and delay time is set to zero (event fires immediately) and duration is set to inifinite time. The note is held while the instrument is producing something. If the instrument is silent for some seconds (specified in the first argument) then it's turned off.
schedUntil :: (Arg a, Sigs b) => (a -> SE b) -> Evt a -> Evt c -> b Source #
Invokes an instrument with first event stream and holds the note until the second event stream is active.
schedToggle :: Sigs b => SE b -> Evt D -> b Source #
Invokes an instrument with toggle event stream (1 stands for on and 0 stands for off).
schedUntil_ :: Arg a => (a -> SE ()) -> Evt a -> Evt c -> SE () Source #
Invokes an instrument with first event stream and holds the note until the second event stream is active.
schedBy :: (Arg a, Sigs b, Arg c) => (a -> SE b) -> (c -> Evt (Sco a)) -> c -> b #
A closure to trigger an instrument inside the body of another instrument.
schedHarpBy :: (Arg a, Sigs b, Arg c) => D -> (a -> SE b) -> (c -> Evt [a]) -> c -> b #
A closure to trigger an instrument inside the body of another instrument.
withDur :: Sig -> Evt a -> Evt (Sco a) Source #
Sets the same duration for all events. It's useful with the functions sched
, schedBy
, sched_
.
Api
We can create named instruments. then we can trigger the named instruments with Csound API. Csound can be used not as a text to audio converter but also as a shared C-library. There are many bindings to many languages. For example we can use Python or Android SDK to create UI and under the hood we can use the audio engine created with Haskell. The concept of named instruments is the bridge for other lnguages to use our haskell-generated code.
trigByName :: (Arg a, Sigs b) => String -> (a -> SE b) -> SE b #
Creates an instrument that can be triggered by name with Csound API.
The arguments are determined from the structure of the input for the instrument.
If we have a tuple of arguments: (D, D, Tab)
The would be rendered to instrument arguments that strts from p4
.
p1
is the name of teh instrument, p2
is the start time of the note,
p3
is the duration of the note. Then p4
and p5
are going to be doubles and p6
is an integer that denotes a functional table.
trigByName_ :: Arg a => String -> (a -> SE ()) -> SE () #
Creates an instrument that can be triggered by name with Csound API. The arguments are determined from the structure of the input for the instrument.
With Csound API we can send messages
i "name" time duration arg1 arg2 arg3
trigByNameMidi :: (Arg a, Sigs b) => String -> ((D, D, a) -> SE b) -> SE b #
Creates an instrument that can be triggered by name with Csound API.
It's intended to be used like a midi instrument. It simulates a simplified midi protocol. We can trigger notes:
i "givenName" delay duration 1 pitchKey volumeKey auxParams -- note on i "givenName" delay duration 0 pitchKey volumeKey auxParams -- note off
The arguments are
trigByNameMidi name instrument
The instrument takes a triplet of (pitchKey, volumeKey, auxilliaryTuple)
.
The order does matter. Please don't pass the volumeKey
as the first argument.
The instrument expects the pitch key to be a first argument.
trigByNameMidi_ :: Arg a => String -> ((D, D, a) -> SE ()) -> SE () #
It behaves just like the function trigByNameMidi
. Only it doesn't produce an audio
signal. It performs some procedure on note on and stops doing the precedure on note off.
turnoffByName :: String -> Sig -> Sig -> SE () Source #
Turns off named instruments.
turnoffNamedInstr name kmode krelease
name of the instrument (should be defined with trigByName
or smth like that).
kmode -- sum of the following values:
0, 1, or 2: turn off all instances (0), oldest only (1), or newest only (2)
4: only turn off notes with exactly matching (fractional) instrument number, rather than ignoring fractional part
8: only turn off notes with indefinite duration (p3 < 0 or MIDI)
krelease -- if non-zero, the turned off instances are allowed to release, otherwise are deactivated immediately (possibly resulting in clicks)
Misc
playWhen :: forall a b. Sigs a => BoolSig -> (b -> SE a) -> b -> SE a Source #
Transforms an instrument from always on to conditional one. The routput instrument plays only when condition is true otherwise it produces silence.
Overload
Converters to make it easier a construction of the instruments.
class AmpInstr a where Source #
Constructs a drum-like instrument. Drum like instrument has a single argument that signifies an amplitude.
type AmpInstrOut a :: * Source #
Instances
AmpInstr Sig Source # | |
Defined in Csound.Control.Overload.SpecInstr type AmpInstrOut Sig :: Type Source # | |
AmpInstr (SE (Sig, Sig)) Source # | |
AmpInstr (SE Sig) Source # | |
AmpInstr (Sig -> (Sig, Sig)) Source # | |
AmpInstr (Sig -> Sig) Source # | |
AmpInstr (Sig -> SE (Sig, Sig)) Source # | |
AmpInstr (Sig -> SE Sig) Source # | |
AmpInstr (D -> (Sig, Sig)) Source # | |
AmpInstr (D -> Sig) Source # | |
AmpInstr (D -> SE (Sig, Sig)) Source # | |
AmpInstr (D -> SE Sig) Source # | |
AmpInstr (Sig, Sig) Source # | |
class CpsInstr a where Source #
Constructs a simple instrument that takes in a tuple of two arguments. They are amplitude and the frequency (in Hz or cycles per second).
type CpsInstrOut a :: * Source #
Instances
CpsInstr ((Sig, Sig) -> (Sig, Sig)) Source # | |
CpsInstr ((Sig, Sig) -> Sig) Source # | |
CpsInstr ((Sig, Sig) -> SE (Sig, Sig)) Source # | |
CpsInstr ((Sig, Sig) -> SE Sig) Source # | |
CpsInstr ((Sig, D) -> (Sig, Sig)) Source # | |
CpsInstr ((Sig, D) -> Sig) Source # | |
CpsInstr ((Sig, D) -> SE (Sig, Sig)) Source # | |
CpsInstr ((Sig, D) -> SE Sig) Source # | |
CpsInstr ((D, Sig) -> (Sig, Sig)) Source # | |
CpsInstr ((D, Sig) -> Sig) Source # | |
CpsInstr ((D, Sig) -> SE (Sig, Sig)) Source # | |
CpsInstr ((D, Sig) -> SE Sig) Source # | |
CpsInstr ((D, D) -> (Sig, Sig)) Source # | |
CpsInstr ((D, D) -> Sig) Source # | |
CpsInstr ((D, D) -> SE (Sig, Sig)) Source # | |
CpsInstr ((D, D) -> SE Sig) Source # | |
CpsInstr (Sig -> (Sig, Sig)) Source # | |
CpsInstr (Sig -> Sig) Source # | |
CpsInstr (Sig -> SE (Sig, Sig)) Source # | |
CpsInstr (Sig -> SE Sig) Source # | |
CpsInstr (D -> (Sig, Sig)) Source # | |
CpsInstr (D -> Sig) Source # | |
CpsInstr (D -> SE (Sig, Sig)) Source # | |
CpsInstr (D -> SE Sig) Source # | |
Imperative instruments
newInstr :: Arg a => (a -> SE ()) -> SE (InstrRef a) #
Creates a new instrument and generates a unique identifier.
scheduleEvent :: Arg a => InstrRef a -> D -> D -> a -> SE () #
Schedules an event for the instrument.
scheduleEvent instrRef delay duration args
The arguments for time values are set in seconds.
turnoff2 :: InstrRef a -> Sig -> Sig -> SE () #
Turns off the note played on the given instrument. Use fractional instrument reference to turn off specific instance.
turnoff2 instrRef mode releaseTime
The mode is sum of the following values:
- 0, 1, or 2: turn off all instances (0), oldest only (1), or newest only (2)
- 4: only turn off notes with exactly matching (fractional) instrument number, rather than ignoring fractional part
- 8: only turn off notes with indefinite duration (idur < 0 or MIDI)
releaseTime
if non-zero, the turned off instances are allowed to release, otherwise are deactivated immediately (possibly resulting in clicks).
negateInstrRef :: InstrRef a -> InstrRef a #
Negates the instrument identifier. This trick is used in Csound to update the instrument arguments while instrument is working.
addFracInstrRef :: D -> D -> InstrRef a -> InstrRef a #
Adds fractional part to the instrument reference. This trick is used in Csound to identify the notes (or specific instrument invokation).
newOutInstr :: (Arg a, Sigs b) => (a -> SE b) -> SE (InstrRef a, b) #
Creates an insturment that produces a value.