Safe Haskell | None |
---|---|
Language | Haskell2010 |
Rendering of Csound files and playing the music in real time.
How are we going to get the sound out of Haskell code?
Instruments are ready and we have written all the scores for them.
Now, it's time to use the rendering functions. We can render haskell expressions
to Csound code. A rendering function takes a value that represents a sound (it's a tuple of signals)
and produces a string with Csound code. It can take a value that represents
the flags for the csound compiler and global settings (Options
).
Then we can save this string to file and convert it to sound with csound compiler
csound -o music.wav music.csd
Or we can play it in real time with -odac flag. It sends the sound directly to soundcard. It's usefull when we are using midi or tweek the parameters in real time with sliders or knobs.
csound -odac music.csd
The main function of this module is renderCsdBy
. Other function are nothing but
wrappers that produce the Csound code and make something useful with it (saving to file,
playing with specific player or in real time).
Synopsis
- class RenderCsd a where
- data CsdArity = CsdArity {}
- renderCsd :: RenderCsd a => a -> IO String
- writeCsd :: RenderCsd a => String -> a -> IO ()
- writeCsdBy :: RenderCsd a => Options -> String -> a -> IO ()
- writeSnd :: RenderCsd a => String -> a -> IO ()
- writeSndBy :: RenderCsd a => Options -> String -> a -> IO ()
- playCsd :: RenderCsd a => (String -> IO ()) -> String -> a -> IO ()
- playCsdBy :: RenderCsd a => Options -> (String -> IO ()) -> String -> a -> IO ()
- mplayer :: RenderCsd a => a -> IO ()
- mplayerBy :: RenderCsd a => Options -> a -> IO ()
- totem :: RenderCsd a => a -> IO ()
- totemBy :: RenderCsd a => Options -> a -> IO ()
- dac :: RenderCsd a => a -> IO ()
- dacBy :: RenderCsd a => Options -> a -> IO ()
- vdac :: RenderCsd a => a -> IO ()
- vdacBy :: RenderCsd a => Options -> a -> IO ()
- csd :: RenderCsd a => a -> IO ()
- csdBy :: RenderCsd a => Options -> a -> IO ()
- saveUserOptions :: Options -> IO ()
- runCabbage :: RenderCsd a => a -> IO ()
- runCabbageBy :: RenderCsd a => Options -> a -> IO ()
- onCard1 :: (Sig -> a) -> Sig -> a
- onCard2 :: (Sig2 -> a) -> Sig2 -> a
- onCard4 :: (Sig4 -> a) -> Sig4 -> a
- onCard6 :: (Sig6 -> a) -> Sig6 -> a
- onCard8 :: (Sig8 -> a) -> Sig8 -> a
- readMacrosString :: String -> String -> Str
- readMacrosDouble :: String -> Double -> D
- readMacrosInt :: String -> Int -> D
Rendering
class RenderCsd a where Source #
Instances
Sigs a => RenderCsd a Source # | |
RenderCsd Patch2 Source # | |
RenderCsd Patch1 Source # | |
Sigs a => RenderCsd [Sco (Mix a)] Source # | |
Sigs a => RenderCsd (Sco (Mix a)) Source # | |
RenderCsd (Source ()) Source # | |
Sigs a => RenderCsd (Source a) Source # | |
RenderCsd (Source (SE ())) Source # | |
Sigs a => RenderCsd (Source (SE a)) Source # | |
RenderCsd (SE ()) Source # | |
Sigs a => RenderCsd (SE a) Source # | |
Sigs a => RenderCsd (a -> Source (SE Sig2)) Source # | |
(Sigs a, Sigs b) => RenderCsd (a -> Source (SE b)) Source # | |
(Sigs a, Sigs b) => RenderCsd (a -> Source b) Source # | |
(Sigs a, Sigs b) => RenderCsd (a -> SE b) Source # | |
(Sigs a, Sigs b) => RenderCsd (a -> b) Source # | |
writeCsd :: RenderCsd a => String -> a -> IO () Source #
Render Csound file and save it to the give file.
writeCsdBy :: RenderCsd a => Options -> String -> a -> IO () Source #
Render Csound file with options and save it to the give file.
writeSnd :: RenderCsd a => String -> a -> IO () Source #
Render Csound file and save result sound to the wav-file.
writeSndBy :: RenderCsd a => Options -> String -> a -> IO () Source #
Render Csound file with options and save result sound to the wav-file.
Playing the sound
playCsd :: RenderCsd a => (String -> IO ()) -> String -> a -> IO () Source #
Renders Csound file, saves it to the given file, renders with csound command and plays it with the given program.
playCsd program file csd
Produces files file.csd
(with renderCsd
) and file.wav
(with csound
) and then invokes:
program "file.wav"
playCsdBy :: RenderCsd a => Options -> (String -> IO ()) -> String -> a -> IO () Source #
Works just like playCsd
but you can supply csound options.
mplayerBy :: RenderCsd a => Options -> a -> IO () Source #
Renders to tmp.csd and tmp.wav and plays with mplayer.
totem :: RenderCsd a => a -> IO () Source #
Renders to tmp.csd and tmp.wav and plays with totem player.
totemBy :: RenderCsd a => Options -> a -> IO () Source #
Renders to tmp.csd and tmp.wav and plays with totem player.
Live performance
dac :: RenderCsd a => a -> IO () Source #
Renders csound code to file tmp.csd
with flags set to -odac
, -iadc
and -Ma
(sound output goes to soundcard in real time).
vdacBy :: RenderCsd a => Options -> a -> IO () Source #
Output to dac with virtual midi keyboard with specified options.
Render and run
csdBy :: RenderCsd a => Options -> a -> IO () Source #
Renders to file tmp.csd
and invokes the csound on it.
Save user options
saveUserOptions :: Options -> IO () #
Saves the user options in the current directory.
If it's saved in the User's home directory it becomes global options.
Render and run with cabbage
runCabbage :: RenderCsd a => a -> IO () Source #
Runs the csound files with cabbage engine. It invokes the Cabbage command line utility and setts all default cabbage flags.
runCabbageBy :: RenderCsd a => Options -> a -> IO () Source #
Runs the csound files with cabbage engine with user defined options. It invokes the Cabbage command line utility and setts all default cabbage flags.
Aliases for type inference
Sometimes the type class RenderCsd
is too whide for us.
It cn be hard to use in the interpreter without explicit signatures.
There are functions to help the type inference.
** For processing inputs
Config with command line arguments
With the functions we can add global config parameters to the rendered file.
We can supply different parameters with --omacro
flag.
An example:
dac $ osc (sig $ readMacrosDouble "FREQ" 440)
Here we define frequency as a global parameter. It's available by name FREQ
.
If we run the program with no flags it would play the default 440 Hz. But we can change that like this:
csound tmp.csd --omacro:FREQ=330
We can update the macro-arguments with flag --omacro:NAME=VALUE
.
readMacrosString :: String -> String -> Str #
readMacrosDouble :: String -> Double -> D #
readMacrosInt :: String -> Int -> D #