csound-expression-typed 0.0.3 → 0.0.4
raw patch · 8 files changed
+56/−22 lines, 8 filesdep ~csound-expression-dynamic
Dependency ranges changed: csound-expression-dynamic
Files
- csound-expression-typed.cabal +2/−2
- src/Csound/Typed/GlobalState.hs +2/−2
- src/Csound/Typed/GlobalState/Elements.hs +4/−1
- src/Csound/Typed/GlobalState/GE.hs +14/−2
- src/Csound/Typed/GlobalState/Instr.hs +15/−0
- src/Csound/Typed/GlobalState/Opcodes.hs +4/−1
- src/Csound/Typed/Render.hs +3/−1
- src/Csound/Typed/Types.hs +12/−13
csound-expression-typed.cabal view
@@ -1,5 +1,5 @@ Name: csound-expression-typed-Version: 0.0.3+Version: 0.0.4 Cabal-Version: >= 1.6 License: BSD3 License-file: LICENSE@@ -25,7 +25,7 @@ Ghc-Options: -Wall Build-Depends: base >= 4, base < 5, ghc-prim, containers, transformers >= 0.3, Boolean >= 0.1.0, colour >= 2.3, data-default,- wl-pprint, stable-maps >= 0.0.3.3, csound-expression-dynamic >= 0.0.3+ wl-pprint, stable-maps >= 0.0.3.3, csound-expression-dynamic >= 0.0.4 Hs-Source-Dirs: src/ Exposed-Modules: Csound.Typed
src/Csound/Typed/GlobalState.hs view
@@ -6,8 +6,8 @@ module Csound.Typed.GlobalState.Cache, -- * Reexports dynamic BandLimited(..), readBandLimited, renderBandLimited,- Instrs(..), IdMap(..),- getIn, chnUpdateUdo, renderGlobals, turnoff+ Instrs(..), IdMap(..), getInstrIds,+ getIn, chnUpdateUdo, renderGlobals, turnoff, turnoff2 ) where import Csound.Typed.GlobalState.Options
src/Csound/Typed/GlobalState/Elements.hs view
@@ -14,7 +14,7 @@ Globals(..), newPersistentGlobalVar, newClearableGlobalVar, renderGlobals, -- * Instruments- Instrs(..), saveInstr, CacheName, makeCacheName, saveCachedInstr,+ Instrs(..), saveInstr, CacheName, makeCacheName, saveCachedInstr, getInstrIds, -- * Src InstrBody, getIn, sendOut, sendChn, sendGlobal, Event(..),@@ -200,6 +200,9 @@ makeCacheName :: a -> IO CacheName makeCacheName = DM.makeDynamicStableName ++getInstrIds :: Instrs -> [InstrId]+getInstrIds = fmap fst . instrsContent ----------------------------------------------------------------- --
src/Csound/Typed/GlobalState/GE.hs view
@@ -8,7 +8,9 @@ -- * Instruments saveAlwaysOnInstr, onInstr, saveUserInstr0, getSysExpr, -- * Total duration- TotalDur(..), getTotalDur, setDuration, setDurationToInfinite,+ TotalDur(..), getTotalDurGE, getTotalDur, setDuration, setDurationToInfinite,+ -- * Notes+ addNote, -- * GEN routines saveGen, -- * Band-limited waves@@ -80,13 +82,14 @@ , midis :: [MidiAssign] , totalDur :: Maybe TotalDur , alwaysOnInstrs :: [InstrId]+ , notes :: [(InstrId, CsdEvent Note)] , userInstr0 :: Dep () , bandLimitedMap :: BandLimitedMap , cache :: Cache GE , guis :: Guis } instance Default History where- def = History def def def def def def def (return ()) def def def+ def = History def def def def def def def def (return ()) def def def data Msg = Msg data MidiAssign = MidiAssign MidiType Channel InstrId@@ -102,6 +105,12 @@ data TotalDur = NumDur Double | InfiniteDur deriving (Eq, Ord) +getTotalDurGE :: GE Double+getTotalDurGE = do+ opt <- getOptions+ dt <- fmap totalDur getHistory+ return $ getTotalDur opt dt+ getTotalDur :: Options -> (Maybe TotalDur) -> Double getTotalDur _ = toDouble . maybe InfiniteDur id where @@ -149,6 +158,9 @@ saveAlwaysOnInstr :: InstrId -> GE () saveAlwaysOnInstr instrId = onAlwaysOnInstrs $ modify (instrId : ) where onAlwaysOnInstrs = onHistory alwaysOnInstrs (\a h -> h { alwaysOnInstrs = a })++addNote :: InstrId -> CsdEvent Note -> GE ()+addNote instrId evt = modifyHistory $ \h -> h { notes = (instrId, evt) : notes h } {- setMasterInstrId :: InstrId -> GE ()
src/Csound/Typed/GlobalState/Instr.hs view
@@ -10,6 +10,8 @@ import Csound.Typed.GlobalState.SE import Csound.Typed.GlobalState.Options import Csound.Typed.GlobalState.Cache+import Csound.Typed.GlobalState.Opcodes(turnoff2)+import Csound.Typed.GlobalState.Elements(getInstrIds) data Arity = Arity { arityIns :: Int@@ -73,4 +75,17 @@ vars <- onGlobals $ zipWithM C.newPersistentGlobalVar rates (replicate arity 0) saveUserInstr0 $ unSE $ (SE . zipWithM_ writeVar vars) =<< as return $ fmap readOnlyVar vars++saveTerminatorInstr :: GE () +saveTerminatorInstr = do+ instrId <- saveInstr =<< terminatorInstr+ dt <- getTotalDurGE+ addNote instrId (dt, 0.01, [])++terminatorInstr :: GE (SE ())+terminatorInstr = do+ ids <- fmap (getInstrIds . instrs) getHistory+ return $ fromDep_ $ mapM_ turnoff2 $ fmap instrIdE ids+ +
src/Csound/Typed/GlobalState/Opcodes.hs view
@@ -6,7 +6,7 @@ -- * trigger an instrument Event(..), event, event_i, appendChn, subinstr, subinstr_, changed, -- * output- out, outs, safeOut, autoOff, turnoff,+ out, outs, safeOut, autoOff, turnoff, turnoff2, -- * vco2 oscili, oscilikt, vco2ft, vco2ift, vco2init, ftgen, -- * times@@ -151,6 +151,9 @@ turnoff :: Monad m => DepT m () turnoff = depT_ $ opcs "turnoff" [(Xr, [])] []++turnoff2 :: Monad m => E -> DepT m ()+turnoff2 instrId = depT_ $ opcs "turnoff2" [(Xr, [Ir, Ir, Ir])] [instrId, 0, 0] ihold :: Monad m => DepT m () ihold = depT_ $ opcs "ihold" [(Xr, [])] []
src/Csound/Typed/Render.hs view
@@ -25,6 +25,7 @@ toCsd :: Tuple a => Options -> SE a -> GE Csd toCsd options sigs = do saveMasterInstr (constArity sigs) (masterExp sigs)+ saveTerminatorInstr renderHistory (outArity sigs) options renderOut_ :: SE () -> IO String@@ -60,11 +61,12 @@ let flags = reactOnMidi hist3 $ csdFlags opt sco = Sco (Just $ getTotalDur opt $ totalDur hist3) (renderGens $ genMap hist3) $- (fmap alwaysOn $ alwaysOnInstrs hist3)+ ((fmap alwaysOn $ alwaysOnInstrs hist3) ++ (getNoteEvents $ notes hist3)) return $ Csd flags orc sco where renderGens = fmap swap . M.toList . idMapContent maybeAppend ma = maybe id (:) ma + getNoteEvents = fmap $ \(instrId, evt) -> (instrId, [evt]) getInstr0 :: Int -> Options -> History -> Dep () getInstr0 nchnls opt hist = do
src/Csound/Typed/Types.hs view
@@ -13,7 +13,6 @@ module Csound.Typed.Types.Evt ) where -import Control.Applicative import qualified Csound.Dynamic as D import Csound.Typed.Types.Prim@@ -28,31 +27,31 @@ -- | Appends initialisation arguments. It's up to user to supply arguments with the right types. For example: -- -- > oscil 0.5 440 sinWave `withInits` (0.5 :: D)-withInits :: (Val a, Tuple b) => a -> b -> a+withInits :: (Tuple a, Tuple b) => a -> b -> a withInits a b = genWithInits a (fromTuple b) -- | A special case of @withInits@. Here all inits are numbers. -withDs :: Val a => a -> [D] -> a+withDs :: Tuple a => a -> [D] -> a withDs a ds = genWithInits a (mapM toGE ds) -- | Appends an init value which is a number.-withD :: Val a => a -> D -> a+withD :: Tuple a => a -> D -> a withD = withInits -- | A special case of @withInits@. Here all inits are signals. -withSigs :: Val a => a -> [Sig] -> a+withSigs :: Tuple a => a -> [Sig] -> a withSigs a sigs = genWithInits a (mapM toGE sigs) -- | Appends an init value which is a signal.-withSig :: Val a => a -> Sig -> a+withSig :: Tuple a => a -> Sig -> a withSig = withInits -- | A special case of @withInits@. Here all inits are arrays. -withTabs :: Val a => a -> [Tab] -> a+withTabs :: Tuple a => a -> [Tab] -> a withTabs a tabs = genWithInits a (mapM toGE tabs) -- | Appends an init value which is a table.-withTab :: Val a => a -> Tab -> a+withTab :: Tuple a => a -> Tab -> a withTab = withInits -- | Applies a seed to the random value. @@ -63,9 +62,9 @@ withSeed :: SE Sig -> D -> Sig withSeed a d = hideGE $ evalSE $ fmap (flip withD d) a -genWithInits :: (Val a) => a -> GE [E] -> a-genWithInits a vals = fromGE $ liftA2 D.withInits (toGE a) vals---+genWithInits :: (Tuple a) => a -> GE [E] -> a+genWithInits a vals = toTuple $ do+ as <- fromTuple a+ vs <- vals+ return $ fmap (\x -> D.withInits x vs) as