Skip to content

Instantly share code, notes, and snippets.

@mikesol
Last active September 25, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesol/d488e591fe57aebffc407ce7435fbf6c to your computer and use it in GitHub Desktop.
Save mikesol/d488e591fe57aebffc407ce7435fbf6c to your computer and use it in GitHub Desktop.
Anamorphism
module Main where
import Prelude
import Data.NonEmpty ((:|))
import Effect (Effect)
import Data.Function (on)
import WAGS.Lib.Learn (play)
import WAGS.Lib.Learn.Note (accelerando, noteFromPitch_, repeat, seq)
import WAGS.Lib.Learn.Pitch (at, fuse, c4, d4, e4, fSharp4, gSharp4, bFlat4, c5, wholeTone)
import WAGS.Lib.Cofree (ana)
main :: Effect Unit
main =
play
$ map fuse
$ (map <<< map) _.note
$ ana
((<*>) \time { note, rising } ->
if on (>=) (at time) note c5 then { note: bFlat4, rising: false }
else if on (<=) (at time) note c4 then { note: d4, rising: true }
else { note: (if rising then add else sub) note wholeTone, rising }
)
(const { note: c4, rising: true })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment