packages feed

essence-of-live-coding-pulse-example (empty) → 0.2.1

raw patch · 4 files changed

+163/−0 lines, 4 filesdep +basedep +essence-of-live-codingdep +essence-of-live-coding-pulse

Dependencies added: base, essence-of-live-coding, essence-of-live-coding-pulse, pulse-simple, transformers, vector

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for essence-of-live-coding-pulse++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2019, Manuel Bärenz++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Manuel Bärenz nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ app/Main.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE Arrows #-}+{-# LANGUAGE TupleSections #-}+module Main where++-- base+import Control.Arrow as X+import Control.Concurrent+import Control.Monad (void)+import Control.Monad.Fix+import qualified Data.List.NonEmpty as NonEmpty+import Data.List.NonEmpty (NonEmpty)++import Prelude hiding ((!))++-- transformers+import Control.Monad.Trans.Reader++-- vector+import qualified Data.Vector as Vector+import Data.Vector ((!))++-- pulse-simple+import Sound.Pulse.Simple++-- essence-of-live-coding+import LiveCoding++-- essence-of-live-coding-pulse+import LiveCoding.Pulse++fastSine :: (Data a, Floating a, MonadFix m) => Cell (ReaderT a m) () a+fastSine = proc _ -> do+  t <- constM ask -< ()+  rec+    let acc = - (2 * pi / t) ^ 2 * pos+    vel <- sumC' <<< delay 0 -< acc+    pos <- arr (+ 1) <<< sumC' -< vel+  returnA -< pos++sumC' :: (Monad m, Data a, Num a) => Cell m a a+sumC' = Cell+  { cellState = 0+  , cellStep  = \accum a -> let accum' = accum + a in return (accum', accum')+  }++cellA :: MonadFix m => Cell m () Float+cellA = runReaderC (44100 / 440) fastSine++cellB :: MonadFix m => Cell m () Float+cellB = proc _ -> do+  fDelta <- runReaderC 10 osc -< ()+  runReaderC' osc -< (440 + 5 * fDelta, ())++short :: Monad m => Float -> CellExcept m () Float ()+short frequency = try $ proc _ -> do+  count <- sumC -< 1 :: Int+  if count > 8000+    then throwC -< ()+    else returnA -< frequency++frequencies :: Monad m => Cell m () Float+frequencies = foreverC $ runCellExcept $ sequence $ (short . f) <$> [C, E, G]++cycleThrough :: Monad m => NonEmpty a -> Int -> Cell m () a+cycleThrough bs cycleLength = let vector = Vector.fromList (NonEmpty.toList bs) in proc _ -> do+  n <- modSum (cycleLength * length bs) -< 1+  returnA -< vector ! (n `div` cycleLength)++frequencies' :: Monad m => Cell m () Float+frequencies' = cycleThrough (NonEmpty.fromList $ [f D, f G, o $ f Bb]) 8000++pulseCell :: Monad m => PulseCell m () ()+pulseCell = frequencies' >>> osc' >>> addSample++liveProgram :: LiveProgram (HandlingStateT IO)+liveProgram = liveCell $ pulseWrapC 1024 pulseCell >>> arr (const ())++main :: IO ()+main = runHandlingStateT $ foreground liveProgram
+ essence-of-live-coding-pulse-example.cabal view
@@ -0,0 +1,49 @@+name:                essence-of-live-coding-pulse-example+version:             0.2.1+synopsis: General purpose live coding framework - pulse backend example+description:+  essence-of-live-coding is a general purpose and type safe live coding framework.+  .+  You can run programs in it, and edit, recompile and reload them while they're running.+  Internally, the state of the live program is automatically migrated when performing hot code swap.+  .+  The library also offers an easy to use FRP interface.+  It is parametrized by its side effects,+  separates data flow cleanly from control flow,+  and allows to develop live programs from reusable, modular components.+  There are also useful utilities for debugging and quickchecking.+  .+  This package contains an example for PulseAudio backend.++license:             BSD3+license-file:        LICENSE+author:              Manuel Bärenz+maintainer:          programming@manuelbaerenz.de+homepage:            https://www.manuelbaerenz.de/#computerscience+category:            FRP, Live coding+build-type:          Simple+extra-source-files:  CHANGELOG.md+cabal-version:       >=1.10++source-repository head+  type:     git+  location: git@github.com:turion/essence-of-live-coding.git++source-repository this+  type:     git+  location: git@github.com:turion/essence-of-live-coding.git+  tag:      v0.2.1+++executable essence-of-live-coding-pulse-example+  main-is:             Main.hs+  build-depends:+      base >= 4.11 && < 5+    , transformers >= 0.5+    , pulse-simple >= 0.1+    , vector >= 0.12+    , essence-of-live-coding >= 0.2.1+    , essence-of-live-coding-pulse >= 0.2.1+  hs-source-dirs:      app+  default-language:    Haskell2010+  default-extensions: StrictData