Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. {-# LANGUAGE ParallelListComp #-}
  2. {-# LANGUAGE RebindableSyntax #-}
  3. module Live where
  4.  
  5. import Control.Concurrent
  6. import Data.Word (Word8)
  7. import Data.Function ((&))
  8. import Prelude
  9. import Data.String
  10.  
  11. import Syzygy.Core
  12. import Syzygy.Signal
  13. import Syzygy.MIDI
  14.  
  15. setup :: IO MIDIConfig
  16. setup = do
  17. signalRef <- newMVar mempty
  18. clockRef <- newMVar 0
  19. bpmRef <- newMVar 120
  20. let midiPortName = "UM-ONE MIDI 1"
  21. -- let midiPortName = "VirMIDI 2-0"
  22. let config = MkMIDIConfig { bpmRef, midiPortName, signalRef, clockRef}
  23. _ <- forkIO $ runBackend backend config
  24. return config
  25.  
  26. main :: IO ()
  27. main = do
  28. MkMIDIConfig {signalRef, bpmRef} <- runOnce setup
  29. modifyMVar_ bpmRef $ const . return $ 160
  30. modifyMVar_ signalRef $ const . return $ sigMod mempty
  31.  
  32. with :: Functor f => (f a -> a) -> f (a -> a) -> a -> a
  33. with cat mods sig = cat $ ($sig) <$> mods
  34.  
  35. infixl 4 `tt`
  36.  
  37. tt :: Rational -> (Signal a -> Signal a) -> Signal a -> Signal a
  38. tt i mod sig = sig
  39. & slow i
  40. & mod
  41. & fast i
  42.  
  43. fracture :: Int -> (Signal a -> Signal a) -> Signal a -> Signal a
  44. fracture n f = foldr (flip (.)) id ([tt (1/(2^i)) f | i <- [0..n]])
  45.  
  46. overlay :: (Signal a -> Signal a) -> (Signal a -> Signal a)
  47. overlay f = with mconcat [id, f]
  48.  
  49. filterSig :: (a -> Bool) -> Signal a -> Signal a
  50. filterSig pred sig = MkSignal $ \query -> signal sig query
  51. & filter (\MkEvent{payload}-> pred payload)
  52.  
  53. lpf :: Word8 -> Signal Word8 -> Signal Word8
  54. lpf i = filterSig $ (<i)
  55.  
  56. hpf :: Word8 -> Signal Word8 -> Signal Word8
  57. hpf i = filterSig $ (>i)
  58.  
  59. staccato :: Signal a -> Signal a
  60. staccato sig = sig & (mapInterval . mapDur) (/4)
  61.  
  62. sigMod :: Signal Word8 -> Signal Word8
  63. sigMod = let (>>) = (flip (.)) in do
  64. const (embed 60)
  65. with switch [ fmap (+(x)) | x <- [-0, 3, 7, 10, 14, 15, 17, 26, 27, 10, 14, 7, 3]]
  66. fast 8
  67. tt (1/4) $ with switch [fmap (subtract x) | x <- [0, 5, 2, 7]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement