essence-of-live-coding-pulse 0.2.6 → 0.2.7
raw patch · 3 files changed
+50/−40 lines, 3 filesdep ~essence-of-live-codingsetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: essence-of-live-coding
API changes (from Hackage documentation)
Files
- Setup.hs +1/−0
- essence-of-live-coding-pulse.cabal +2/−2
- src/LiveCoding/Pulse.hs +47/−38
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
essence-of-live-coding-pulse.cabal view
@@ -1,5 +1,5 @@ name: essence-of-live-coding-pulse-version: 0.2.6+version: 0.2.7 synopsis: General purpose live coding framework - pulse backend description: essence-of-live-coding is a general purpose and type safe live coding framework.@@ -30,7 +30,7 @@ LiveCoding.Pulse build-depends: base >= 4.11 && < 5- , essence-of-live-coding >= 0.2.6+ , essence-of-live-coding >= 0.2.7 , transformers >= 0.5 , pulse-simple >= 0.1 , foreign-store >= 0.2
src/LiveCoding/Pulse.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE Arrows #-}+ module LiveCoding.Pulse where -- base@@ -6,10 +7,10 @@ import Control.Concurrent import Control.Monad (forever) import Control.Monad.Fix-import Data.Monoid (getSum, Sum(Sum))+import Data.Monoid (Sum (Sum), getSum) -- transformers-import Control.Monad.Trans.Class (MonadTrans(lift))+import Control.Monad.Trans.Class (MonadTrans (lift)) import Control.Monad.Trans.Reader import Control.Monad.Trans.Writer.Strict @@ -38,18 +39,20 @@ this might be configurable. -} pulseHandle :: Handle IO Simple-pulseHandle = Handle- { create = simpleNew- Nothing- "example"- Play- Nothing- "this is an example application"- (SampleSpec (F32 LittleEndian) sampleRate 1)- Nothing- Nothing- , destroy = simpleFree- }+pulseHandle =+ Handle+ { create =+ simpleNew+ Nothing+ "example"+ Play+ Nothing+ "this is an example application"+ (SampleSpec (F32 LittleEndian) sampleRate 1)+ Nothing+ Nothing+ , destroy = simpleFree+ } {- | Run a 'PulseCell' with a started pulse backend. @@ -59,12 +62,12 @@ This performs several steps of your cell at a time, replicating the input so many times. -}-pulseWrapC- :: Int- -- ^ Specifies how many steps of your 'PulseCell' should be performed in one step of 'pulseWrapC'.- -> PulseCell IO a b- -- ^ Your cell that produces samples.- -> Cell (HandlingStateT IO) a [b]+pulseWrapC ::+ -- | Specifies how many steps of your 'PulseCell' should be performed in one step of 'pulseWrapC'.+ Int ->+ -- | Your cell that produces samples.+ PulseCell IO a b ->+ Cell (HandlingStateT IO) a [b] pulseWrapC bufferSize cell = proc a -> do simple <- handling pulseHandle -< () samplesAndBs <- resampleList $ liftCell $ runWriterC cell -< replicate bufferSize a@@ -79,35 +82,40 @@ This is to prevent floating number imprecision when the sum gets too large. -} wrapSum :: (Monad m, Data a, RealFloat a) => Cell m a a-wrapSum = Cell- { cellState = 0- , cellStep = \accum a ->- let- (_, accum') = properFraction $ accum + a- in return (accum', accum')- }+wrapSum =+ Cell+ { cellState = 0+ , cellStep = \accum a ->+ let+ (_, accum') = properFraction $ accum + a+ in+ return (accum', accum')+ } -- | Like 'wrapSum', but as an integral, assuming the PulseAudio 'sampleRate'. wrapIntegral :: (Monad m, Data a, RealFloat a) => Cell m a a wrapIntegral = arr (/ sampleRate) >>> wrapSum --- | A sawtooth, or triangle wave, generator,--- outputting a sawtooth wave with the given input as frequency.+{- | A sawtooth, or triangle wave, generator,+ outputting a sawtooth wave with the given input as frequency.+-} sawtooth :: (Monad m, Data a, RealFloat a) => Cell m a a sawtooth = wrapIntegral modSum :: (Monad m, Data a, Integral a) => a -> Cell m a a-modSum denominator = Cell- { cellState = 0- , cellStep = \accum a -> let accum' = (accum + a) `mod` denominator in return (accum', accum')- }+modSum denominator =+ Cell+ { cellState = 0+ , cellStep = \accum a -> let accum' = (accum + a) `mod` denominator in return (accum', accum')+ } clamp :: (Ord a, Num a) => a -> a -> a -> a clamp lower upper a = min upper $ max lower a --- | A sine oscillator.--- Supply the frequency via the 'ReaderT' environment.--- See 'osc'' and 'oscAt'.+{- | A sine oscillator.+ Supply the frequency via the 'ReaderT' environment.+ See 'osc'' and 'oscAt'.+-} osc :: (Data a, RealFloat a, Monad m) => Cell (ReaderT a m) () a osc = proc _ -> do f <- constM ask -< ()@@ -143,8 +151,9 @@ | Gis deriving (Enum, Show) --- | Calculate the frequency of a note,--- with 'A' corresponding to 220 Hz.+{- | Calculate the frequency of a note,+ with 'A' corresponding to 220 Hz.+-} f :: Note -> Float f note = 220 * (2 ** (fromIntegral (fromEnum note) / 12))