packages feed

csound-expression 0.3.1 → 0.3.2

raw patch · 9 files changed

+194/−51 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- CsoundExpr.Base.Header: ftgen :: Irate -> Irate -> Irate -> [Irate] -> Irate
+ CsoundExpr.Base.Gens: toFtgen :: Irate -> Irate
+ CsoundExpr.Base.Gens: toFtgenonce :: Irate -> Irate
+ CsoundExpr.Base.Gens: toFtgentmp :: Irate -> Irate
+ CsoundExpr.Opcodes.Other: filebit :: [Irate] -> String -> Irate
- CsoundExpr.Base.Gens: gen11 :: Int -> [Double] -> Irate
+ CsoundExpr.Base.Gens: gen11 :: Int -> Int -> [Double] -> Irate
- CsoundExpr.Base.Gens: gen11'12 :: Integer -> [Double] -> Irate
+ CsoundExpr.Base.Gens: gen11'12 :: Integer -> Int -> [Double] -> Irate
- CsoundExpr.Base.Gens: gen11'2 :: Integer -> [Double] -> Irate
+ CsoundExpr.Base.Gens: gen11'2 :: Integer -> Int -> [Double] -> Irate

Files

Changelog view
@@ -1,9 +1,19 @@--- 0.3.0    update for Score api. Now there is no Score api by default.+-> 0.3.2    adds new GEN functionality:+			new functions for specific gens creation: +				toFtgen, toFtgentmp, toFtgenonce	+			skipNorm accepts not only values created with genXX,+			but gen-like values also (created with toFtgenXXX functions)++-> 0.3.1    underlying temporal-media package updates++-> 0.3.0    update for Score api. Now there is no Score api by default. 			Consider using 'temporal-media'[1] or 'temporal-music-notation'[2] 			packages for csound score events composition.  			'temporal-media' is general package for functional construction  			of list of events with fixed start time and duration, like 			csound notes. ++			Tutorial moves to root-module 'CsoundExpr'.  			[1] http://hackage.haskell.org/package/temporal-media 			[2] http://hackage.haskell.org/package/temporal-music-notation
csound-expression.cabal view
@@ -1,5 +1,5 @@ Name:          csound-expression-Version:       0.3.1+Version:       0.3.2 Cabal-Version: >= 1.2 License:       BSD3 License-File:  LICENSE@@ -56,6 +56,9 @@  -- Opcodes         CsoundExpr.Opcodes+        +        CsoundExpr.Opcodes.Other+         CsoundExpr.Opcodes.Siggen         CsoundExpr.Opcodes.Sigio         CsoundExpr.Opcodes.Sigmod
src/CsoundExpr.hs view
@@ -180,16 +180,28 @@         to 'csd' function by invoking 'csd' with @'none' t@         ('temporal-media') or @(toList $ 'rest' t)@ ('temporal-music-notation')         in place of 'EventList' value.++        Csound statement @f 0 n@ is always present in generated .csd file.+        Here @n@ is score's duration. +         -        >flags = "-odac -iadc  -+rtmidi=virtual -M0"+        >import Temporal.Music.Notation         >+        >import CsoundExpr+        >import CsoundExpr.Opcodes+        >+        >flags = "-odac -d  -+rtmidi=virtual -M0"+        >         >header = [massign [] 1 instrMidi]         >         >instrMidi :: SignalOut-        >instrMidi = out $ oscilA [] (num 1000) cpsmidi $ gen10 4096 [1]+        >instrMidi = out $ oscilA [] (num 5000) cpsmidi $ gen10 4096 [1]         >-        >-- play instrMidi for 2 minutes-        >exmpMidi = print $ csd flags header (none 120)+        >res = csd flags header $ renderScore (rest 3600)+        >+        >-- play: requires tmp folder in current directory+        >main = do+        >    playDac "tmp" "new" res     -}      -- * Limits
src/CsoundExpr/Base/Gens.hs view
@@ -8,7 +8,14 @@ -- module CsoundExpr.Base.Gens   (-             skipNorm,+             skipNorm, +             +-- * Specific gens++-- | Converts values created with genXXs to some specific GEN form.+--+-- >q = toFtgentmp $ gen10 4096 [1]+             toFtgen, toFtgentmp, toFtgenonce, -- * Empty table (csound f0)              ftempty, -- * Sine/Cosine generators@@ -37,8 +44,11 @@     -- >genXX'2  = genXX . (2^)   -             gen09'2,  gen10'2,  gen11'2,  gen19'2,  gen30'2,  gen33'2,  gen34'2, -             gen05'2, gen06'2, gen07'2, gen08'2, gen16'2, gen25'2, gen27'2, +             gen09'2,  gen10'2,  gen11'2,  gen19'2,  +             gen30'2,  gen33'2,  gen34'2, ++             gen05'2, gen06'2, gen07'2, gen08'2, +             gen16'2, gen25'2, gen27'2,               gen01'2, gen23'2, gen28'2,              gen02'2, gen17'2,              gen20'2,@@ -51,8 +61,12 @@     -- | Gens size is power of two plus one     --     -- >genXX'12 = genXX . (+1) . (2^)-             gen09'12, gen10'12, gen11'12, gen19'12, gen30'12, gen33'12, gen34'12,-             gen05'12, gen06'12, gen07'12, gen08'12, gen16'12, gen25'12, gen27'12, +             gen09'12, gen10'12, gen11'12, gen19'12, +             gen30'12, gen33'12, gen34'12,++             gen05'12, gen06'12, gen07'12, gen08'12, +             gen16'12, gen25'12, gen27'12, +              gen01'12, gen23'12, gen28'12,              gen02'12, gen17'12,              gen20'12,@@ -65,7 +79,11 @@ )  where + import CsoundExpr.Base.SideEffect+import CsoundExpr.Base.UserDefined+import CsoundExpr.Base.Arithmetic+ import CsoundExpr.Translator.Types import CsoundExpr.Translator.ExprTree.ExprTree import CsoundExpr.Translator.Cs.CsTree@@ -79,23 +97,88 @@ gen :: IM CsTree a => Id -> Size -> [CsTree] -> a  gen id n = ftable . Ftable n . GEN id -genD :: Id -> Size -> [Double] -> Irate-genD id n = gen id n . map ftvalD+genD :: IM CsTree a => Id -> Size -> [Double] -> a+genD id n = gen id n . map double -ftvalI :: Int -> CsTree-ftvalI = int-ftvalD = double-ftvalS = string+genXD :: IM CsTree b => Id -> (a -> CsTree) -> Size -> a -> [Double] -> b+genXD id fun n v vs = gen id n $ fun v : map double vs -ftvalF :: Irate -> CsTree-ftvalF = ftable . getFtable . to+ftval :: Irate -> CsTree+ftval = ftable . getFtable . to --- | skip normalization+-- | skip normalization. It can be applied to values created +-- with genXX functions or genXX-like values (i.e. things+-- converted from genXX to specific gens, or things created+-- with genXX'NN) skipNorm :: Irate -> Irate-skipNorm = from . mapFtable skip . to-    where skip (Ftable n (GEN id xs)) = Ftable n $ GEN (-(abs id)) xs-               +skipNorm x +    | isFtable' h = from $ mapFtable skipFt $ to x+    | isOpc     h = from $ skipOpc h t +    | otherwise   = skipErrorMsg+    where (h, t) = decompCsTree $ to x ++isFtable' :: CsExpr -> Bool+isFtable' x +    | isVal x   = isFtable $ value x+    | otherwise = False+++skipErrorMsg = error "skipNorm argument should be genXX or gen-like value"++skipFt :: Ftable -> Ftable+skipFt x = case x of+              (Ftable n (GEN id xs)) -> Ftable n $ GEN (-(abs id)) xs+              _                      -> x++skipOpc :: CsExpr -> [CsTree] -> CsTree+skipOpc h args+    | isGenLike h = pure h $ skipGenId args+    | otherwise   = skipErrorMsg+++isGenLike :: CsExpr -> Bool+isGenLike = (`elem` ["ftgen", "ftgentmp", "ftgenonce"]) . opcName++skipGenId :: [CsTree] -> [CsTree]+skipGenId xs = take 3 xs ++ (skipElem $ xs !! 3) : drop 4 xs+    where skipElem = int . negate . abs . +                      (\(ValueInt x) -> x) . value . getCsExpr+++-- | converts values created with genXX +-- to 'ftgen' csound opcode representation.+-- Two first arguments assigned to zero.+toFtgen :: Irate -> Irate+toFtgen = fromGen "ftgen"++-- | converts values created with genXX +-- to 'ftgentmp' csound opcode representation.+-- Two first arguments assigned to zero.+toFtgentmp :: Irate -> Irate+toFtgentmp = fromGen "ftgentmp"++-- | converts values created with genXX +-- to 'ftgenonce' csound opcode representation.+-- Two first arguments assigned to zero.+toFtgenonce :: Irate -> Irate+toFtgenonce = fromGen "ftgenonce" ++fromGen :: String -> Irate -> Irate+fromGen name x = opcode name args+    where args = int 0 : int 0 : int n : int id : xs+          (Ftable n (GEN id xs)) = errorIfEmpty $ getFtable $ to x++errorIfEmpty :: Ftable -> Ftable+errorIfEmpty x = +    case x of+        EmptyFtable -> error msg+        _           -> x+    where msg = "conversion is possible for non-empty ftables only"+    +++ -- Sine/Cosine generators --    gen09, gen10, gen11, gen19, gen30, gen33, gen34, @@ -121,8 +204,8 @@ -- | GEN11 - Additive set of cosine partials. -- -- url : <http://www.csounds.com/manual/html/GEN11.html>-gen11 :: Int -> [Double] -> Irate-gen11 = genD 11+gen11 :: Int -> Int -> [Double] -> Irate+gen11 = genXD 11 int  -- | GEN19 - Composite waveforms made up of weighted sums of simple sinusoids. --@@ -135,24 +218,20 @@ -- -- url : <http://www.csounds.com/manual/html/GEN30.html> gen30 :: Int -> Irate -> [Double] -> Irate-gen30 = gen3x 30+gen30 = genXD 30 ftval  -- | GEN33 - Generate composite waveforms by mixing simple sinusoids. -- -- url : <http://www.csounds.com/manual/html/GEN33.html> gen33 :: Int -> Irate -> [Double] -> Irate-gen33 = gen3x 33+gen33 = genXD 33 ftval   -- | GEN34 - Generate composite waveforms by mixing simple sinusoids. -- -- url : <http://www.csounds.com/manual/html/GEN34.html> gen34 :: Int -> Irate -> [Double] -> Irate-gen34 = gen3x 34--gen3x :: Int -> Int -> Irate -> [Double] -> Irate-gen3x id n ft vs = gen id n $ [ftvalF ft] ++ map ftvalD vs-+gen34 = genXD 34 ftval  -- Line/Exponential Segment Generators: --      gen05, gen06, gen07, gen08, gen16, gen25, gen27, @@ -213,19 +292,19 @@ -- -- url : <http://www.csounds.com/manual/html/GEN01.html> gen01 :: Int -> String -> [Double] -> Irate-gen01 n file xs = gen 1 n $ [ftvalS file] ++ map ftvalD xs+gen01 = genXD 1 string   -- | GEN23 - Reads numeric values from a text file. -- -- url : <http://www.csounds.com/manual/html/GEN23.html> gen23 :: Int -> String -> Irate-gen23 n file = gen 23 n [ftvalS file]+gen23 n file = gen 23 n [string file]  -- | GEN28 - Reads a text file which contains a time-tagged trajectory. -- -- url : <http://www.csounds.com/manual/html/GEN28.html> gen28 :: Int -> String -> Irate-gen28 n file = gen 28 n [ftvalS file]+gen28 n file = gen 28 n [string file]   -- Numeric Value Access GEN Routines@@ -260,31 +339,31 @@ -- -- url : <http://www.csounds.com/manual/html/GEN21.html> gen21 :: Int -> [Double] -> SideEffect Irate-gen21 = gen21 +gen21 = genD 21   -- | GEN41 - Generates a random list of numerical pairs. -- -- url : <http://www.csounds.com/manual/html/GEN41.html> gen41 :: Int -> [Double] -> SideEffect Irate-gen41 = gen41 +gen41 = genD 41   -- | GEN42 - Generates a random distribution of discrete ranges of values. -- -- url : <http://www.csounds.com/manual/html/GEN42.html> gen42 :: Int -> [Double] -> SideEffect Irate-gen42 = gen42 +gen42 = genD 42   -- | GEN40 - Generates a random distribution using a distribution histogram. -- -- url : <http://www.csounds.com/manual/html/GEN40.html> gen40 :: Int -> Irate -> SideEffect Irate-gen40 n ft = gen 40 n [ftvalF ft]+gen40 n ft = gen 40 n [ftval ft]  -- | GEN43 - Loads a PVOCEX file containing a PV analysis. -- -- url : <http://www.csounds.com/manual/html/GEN43.html> gen43 :: Int -> String -> [Double] -> Irate-gen43 n file vs = gen 43 n $ [ftvalS file] ++ map ftvalD vs+gen43 = genXD 43 string   -- Waveshaping GEN Routines@@ -328,13 +407,13 @@ -- -- url : <http://www.csounds.com/manual/html/GEN04.html> gen04 :: Int -> Irate -> [Double] -> Irate-gen04 n ft vs = gen 4  n $ [ftvalF ft] ++ map ftvalD vs+gen04 = genXD 4 ftval  -- | GEN24 - Reads numeric values from another allocated function-table and rescales them. -- -- url : <http://www.csounds.com/manual/html/GEN24.html> gen24 :: Int -> Irate -> [Double] -> Irate-gen24 n ft vs = gen 24 n $ [ftvalF ft] ++ map ftvalD vs+gen24 = genXD 24 ftval   -- Mixing GEN Routines@@ -345,20 +424,20 @@ -- url : <http://www.csounds.com/manual/html/GEN18.html> gen18 :: Int -> [(Irate, Double, Int, Int)] -> Irate gen18 n xs = gen 18 n (f =<< xs)-    where f (x1, x2, x3, x4) = [ftvalF x1, ftvalD x2, ftvalI x3, ftvalI x4]+    where f (x1, x2, x3, x4) = [ftval x1, double x2, int x3, int x4]  -- | GEN31 - Mixes any waveform specified in an existing table. -- -- url : <http://www.csounds.com/manual/html/GEN31.html> gen31 :: Int -> Irate -> [Double] -> Irate-gen31 n ft vs = gen 31 n $ [ftvalF ft] ++ map ftvalD vs+gen31 = genXD 31 ftval  -- | GEN32 - Mixes any waveform, resampled with either FFT or linear interpolation. -- -- url : <http://www.csounds.com/manual/html/GEN32.html> gen32 :: Int -> [(Irate, Int, Double, Double)] -> Irate gen32 n xs = gen 32 n (f =<< xs)-    where f (x1, x2, x3, x4) = [ftvalF x1, ftvalI x2, ftvalD x3, ftvalD x4]+    where f (x1, x2, x3, x4) = [ftval x1, int x2, double x3, double x4]  -------------------------------------------------------------- --
src/CsoundExpr/Base/Header.hs view
@@ -13,7 +13,7 @@       -- * Header opcodes         instr0,       initA, initK, initI,-      seed, ctrlinit, ftgen,+      seed, ctrlinit,        -- * Constants        -- | (gSr = 44100, gKr = 4410, gKsmps = 10)@@ -134,11 +134,11 @@ -- @ifn@ - is set to zero --  -- > ftgen itime isize igen [iargs]-+{- ftgen :: Irate -> Irate -> Irate -> [Irate] -> Irate ftgen itime isize igen inits = opcode "ftgen" args     where args = [int 0, to itime, to isize, to igen] ++ map to inits-+-}   headerMono :: Header
src/CsoundExpr/Opcodes.hs view
@@ -1,6 +1,9 @@ -- | Csound opcodes module CsoundExpr.Opcodes-    (module CsoundExpr.Opcodes.Siggen,+    (+     module CsoundExpr.Opcodes.Other,     +     +     module CsoundExpr.Opcodes.Siggen,      module CsoundExpr.Opcodes.Sigio,      module CsoundExpr.Opcodes.Sigmod,      module CsoundExpr.Opcodes.Control,@@ -19,7 +22,7 @@      module CsoundExpr.Opcodes.Miscopcodes) where -+import CsoundExpr.Opcodes.Other  import CsoundExpr.Opcodes.Siggen import CsoundExpr.Opcodes.Sigio
+ src/CsoundExpr/Opcodes/Other.hs view
@@ -0,0 +1,26 @@+module CsoundExpr.Opcodes.Other(+        filebit) +where++import CsoundExpr.Base.Types+import CsoundExpr.Base.MultiOut+import CsoundExpr.Base.SideEffect+import CsoundExpr.Base.UserDefined+++-- | * opcode : filebit+--  +--  +-- * syntax : +--+-- >ir filebit ifilcod [, iallowraw]+--+-- * description :+--+-- Returns the number of bits in each sample in a sound file.+--+--+-- * url : <http://www.csounds.com/manual/html/filebit.html>+filebit :: [Irate] -> String -> Irate+filebit inits file = opcode "filebit" args+    where args = [to file] ++ map to inits
src/CsoundExpr/Opcodes/SignalFlowGraphOpcodes/SignalFlowGraphOpcodes.hs view
src/CsoundExpr/Translator/Cs/CsTree.hs view
@@ -18,6 +18,7 @@      equalStructure, equalStructureByParams,    -- selectors      toFtable, ftableGENArgs, ftableSize, ftableGENId, getFtable, +     getCsExpr, getCsArgs, decompCsTree,      mapFtable, toDouble, opcName, oprName, paramId, value,       argName, argRate     )@@ -120,10 +121,19 @@ 			   _                     -> error "value is not ftable"  getFtable :: CsTree -> Ftable-getFtable = select . exprOp . exprTreeTag+getFtable = select . getCsExpr     where select x = case x of                        (Val (ValueFtable x)) -> x                        _                     -> error "value is not ftable"++getCsExpr :: CsTree -> CsExpr+getCsExpr = exprOp . exprTreeTag++getCsArgs :: CsTree -> [CsTree]+getCsArgs = treeChilds++decompCsTree :: CsTree -> (CsExpr, [CsTree])+decompCsTree x = (getCsExpr x, getCsArgs x)  ----------------------------------------------------------- -- CsExpr selectors