diff --git a/CHANGELOG.md b/CHANGELOG.md index 586bccea..ad3644a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.2.1] - 2021-06-02 + +### Added + +- An `icont` function for easier continuations using indexed monads. + ## [0.2.0] - 2021-06-02 ### Changed diff --git a/examples/kitchen-sink/KitchenSink/TLP/DynamicsCompressor.purs b/examples/kitchen-sink/KitchenSink/TLP/DynamicsCompressor.purs index 121db1d4..d8275e9e 100644 --- a/examples/kitchen-sink/KitchenSink/TLP/DynamicsCompressor.purs +++ b/examples/kitchen-sink/KitchenSink/TLP/DynamicsCompressor.purs @@ -1,14 +1,14 @@ module WAGS.Example.KitchenSink.TLP.DynamicsCompressor where import Prelude +import Control.Applicative.Indexed (ipure) import Control.Monad.Indexed.Qualified as Ix import Data.Either (Either(..)) import Math ((%)) import Type.Proxy (Proxy(..)) import WAGS.Change (ichange) import WAGS.Connect (iconnect) -import WAGS.Control.Functions (ibranch, iwag) -import WAGS.Control.Indexed (wag) +import WAGS.Control.Functions (ibranch, icont) import WAGS.Create (icreate) import WAGS.Destroy (idestroy) import WAGS.Disconnect (idisconnect) @@ -23,7 +23,7 @@ doDynamicsCompressor = ibranch \{ time } l@{ loop: LoopSig lsig, iteration } -> if time % pieceTime < timing.ksDynamicsCompressor.begin then Left - $ iwag Ix.do + $ icont lsig Ix.do let cursorCompressor = Proxy :: Proxy "compressor" @@ -34,6 +34,6 @@ doDynamicsCompressor = idestroy cursorPlayBuf icreate ksSinOscCreate iconnect { source: Proxy :: _ "sinOsc", dest: cursorGain } - lsig <$> (wag l { iteration = iteration + 1 }) + ipure $ l { iteration = iteration + 1 } else Right (ichange (deltaKsDynamicsCompressor time) $> l) diff --git a/examples/kitchen-sink/KitchenSink/TLP/Highpass.purs b/examples/kitchen-sink/KitchenSink/TLP/Highpass.purs index e84e31cf..6d68b7f9 100644 --- a/examples/kitchen-sink/KitchenSink/TLP/Highpass.purs +++ b/examples/kitchen-sink/KitchenSink/TLP/Highpass.purs @@ -1,14 +1,15 @@ module WAGS.Example.KitchenSink.TLP.Highpass where import Prelude + +import Control.Applicative.Indexed (ipure) import Control.Monad.Indexed.Qualified as Ix import Data.Either (Either(..)) import Math ((%)) import Type.Proxy (Proxy(..)) import WAGS.Change (ichange) import WAGS.Connect (iconnect) -import WAGS.Control.Functions (ibranch, iwag) -import WAGS.Control.Indexed (wag) +import WAGS.Control.Functions (ibranch, icont) import WAGS.Create (icreate) import WAGS.Destroy (idestroy) import WAGS.Disconnect (idisconnect) @@ -26,7 +27,7 @@ doHighpass = Right (ichange (deltaKsHighpass time) $> lsig) else Left - $ iwag Ix.do + $ icont doMicrophone Ix.do let cursorHighpass = Proxy :: _ "highpass" @@ -37,4 +38,4 @@ doHighpass = idestroy cursorPlayBuf icreate ksMicrophoneCreate iconnect { source: Proxy :: _ "microphone", dest: cursorGain } - doMicrophone <$> wag lsig + ipure lsig diff --git a/src/WAGS/Control/Functions.purs b/src/WAGS/Control/Functions.purs index a5dd22bc..6349c02d 100644 --- a/src/WAGS/Control/Functions.purs +++ b/src/WAGS/Control/Functions.purs @@ -14,6 +14,7 @@ module WAGS.Control.Functions , branch , ibranch , iwag + , icont , freeze , (@>) , (@!>) @@ -25,7 +26,6 @@ module WAGS.Control.Functions ) where import Prelude - import Control.Comonad (extract) import Data.Either (Either(..)) import Data.Map as M @@ -229,14 +229,26 @@ branch :: branch fa w = makeScene (fa w) (branch fa) iwag :: - forall env audio engine proof res graph grapho a. + forall env audio engine proof res graphi grapho a. Monoid res => AudioInterpret audio engine => - IxWAG audio engine proof res { | graph } { | grapho } (Scene env audio engine proof res) -> - WAG audio engine proof res { | graph } a -> + IxWAG audio engine proof res { | graphi } { | grapho } (Scene env audio engine proof res) -> + WAG audio engine proof res { | graphi } a -> Scene env audio engine proof res iwag (IxWAG x) w = extract (x w) +icont :: + forall env audio engine proof res graphi grapho a b. + Monoid res => + AudioInterpret audio engine => + ( WAG audio engine proof res { | grapho } b -> + Scene env audio engine proof res + ) -> + IxWAG audio engine proof res { | graphi } { | grapho } b -> + WAG audio engine proof res { | graphi } a -> + Scene env audio engine proof res +icont c (IxWAG x) = c <<< x + ibranch :: forall env audio engine proofA res graph a. Monoid res => @@ -348,4 +360,4 @@ imodifyRes :: forall audio engine proof res i. AudioInterpret audio engine => (res -> res) -> IxWAG audio engine proof res i i res -imodifyRes f = IxWAG (modifyRes f) \ No newline at end of file +imodifyRes f = IxWAG (modifyRes f)