csound-expression-5.4.0: library to make electronic music
Safe HaskellNone
LanguageHaskell2010

Csound.IO

Description

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

Rendering

class RenderCsd a where Source #

Instances

Instances details
Sigs a => RenderCsd a Source # 
Instance details

Defined in Csound.IO

RenderCsd Patch2 Source # 
Instance details

Defined in Csound.Air.Patch

RenderCsd Patch1 Source # 
Instance details

Defined in Csound.Air.Patch

Sigs a => RenderCsd [Sco (Mix a)] Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> [Sco (Mix a)] -> IO String Source #

csdArity :: [Sco (Mix a)] -> CsdArity Source #

Sigs a => RenderCsd (Sco (Mix a)) Source # 
Instance details

Defined in Csound.IO

RenderCsd (Source ()) Source # 
Instance details

Defined in Csound.IO

Sigs a => RenderCsd (Source a) Source # 
Instance details

Defined in Csound.IO

RenderCsd (Source (SE ())) Source # 
Instance details

Defined in Csound.IO

Sigs a => RenderCsd (Source (SE a)) Source # 
Instance details

Defined in Csound.IO

RenderCsd (SE ()) Source # 
Instance details

Defined in Csound.IO

Sigs a => RenderCsd (SE a) Source # 
Instance details

Defined in Csound.IO

Sigs a => RenderCsd (a -> Source (SE Sig2)) Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> (a -> Source (SE Sig2)) -> IO String Source #

csdArity :: (a -> Source (SE Sig2)) -> CsdArity Source #

(Sigs a, Sigs b) => RenderCsd (a -> Source (SE b)) Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> (a -> Source (SE b)) -> IO String Source #

csdArity :: (a -> Source (SE b)) -> CsdArity Source #

(Sigs a, Sigs b) => RenderCsd (a -> Source b) Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> (a -> Source b) -> IO String Source #

csdArity :: (a -> Source b) -> CsdArity Source #

(Sigs a, Sigs b) => RenderCsd (a -> SE b) Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> (a -> SE b) -> IO String Source #

csdArity :: (a -> SE b) -> CsdArity Source #

(Sigs a, Sigs b) => RenderCsd (a -> b) Source # 
Instance details

Defined in Csound.IO

Methods

renderCsdBy :: Options -> (a -> b) -> IO String Source #

csdArity :: (a -> b) -> CsdArity Source #

data CsdArity Source #

Constructors

CsdArity 

Instances

Instances details
Eq CsdArity Source # 
Instance details

Defined in Csound.IO

Show CsdArity Source # 
Instance details

Defined in Csound.IO

renderCsd :: RenderCsd a => a -> IO String Source #

Renders Csound file.

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.

mplayer :: RenderCsd a => a -> IO () Source #

Renders to tmp.csd and tmp.wav and plays with mplayer.

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

dacBy :: RenderCsd a => Options -> a -> IO () Source #

dac with options.

vdac :: RenderCsd a => a -> IO () Source #

Output to dac with virtual midi keyboard.

vdacBy :: RenderCsd a => Options -> a -> IO () Source #

Output to dac with virtual midi keyboard with specified options.

Render and run

csd :: RenderCsd a => a -> IO () Source #

Renders to file tmp.csd and invokes the csound on it.

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

onCard1 :: (Sig -> a) -> Sig -> a Source #

Alias to process inputs of single input audio-card.

onCard2 :: (Sig2 -> a) -> Sig2 -> a Source #

Alias to process inputs of stereo input audio-card.

onCard4 :: (Sig4 -> a) -> Sig4 -> a Source #

Alias to process inputs of audio-card with 4 inputs.

onCard6 :: (Sig6 -> a) -> Sig6 -> a Source #

Alias to process inputs of audio-card with 6 inputs.

onCard8 :: (Sig8 -> a) -> Sig8 -> a Source #

Alias to process inputs of audio-card with 8 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.