Skip to content

Commit

Permalink
Adds icont
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Solomon committed Jun 2, 2021
1 parent a14cacc commit cd13b19
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/kitchen-sink/KitchenSink/TLP/DynamicsCompressor.purs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"

Expand All @@ -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)
9 changes: 5 additions & 4 deletions examples/kitchen-sink/KitchenSink/TLP/Highpass.purs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -26,7 +27,7 @@ doHighpass =
Right (ichange (deltaKsHighpass time) $> lsig)
else
Left
$ iwag Ix.do
$ icont doMicrophone Ix.do
let
cursorHighpass = Proxy :: _ "highpass"

Expand All @@ -37,4 +38,4 @@ doHighpass =
idestroy cursorPlayBuf
icreate ksMicrophoneCreate
iconnect { source: Proxy :: _ "microphone", dest: cursorGain }
doMicrophone <$> wag lsig
ipure lsig
22 changes: 17 additions & 5 deletions src/WAGS/Control/Functions.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module WAGS.Control.Functions
, branch
, ibranch
, iwag
, icont
, freeze
, (@>)
, (@!>)
Expand All @@ -25,7 +26,6 @@ module WAGS.Control.Functions
) where

import Prelude

import Control.Comonad (extract)
import Data.Either (Either(..))
import Data.Map as M
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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)
imodifyRes f = IxWAG (modifyRes f)

0 comments on commit cd13b19

Please sign in to comment.